In a Laravel Blade file, you can convert a string to lowercase or uppercase using PHP functions directly in the Blade syntax.
Convert to Lowercase
Use the strtolower() function:
{{ strtolower("Hello World") }} <!-- Output: hello world -->
Convert to Uppercase
Use the strtoupper() function:
{{ strtoupper("Hello World") }} <!-- Output: HELLO WORLD -->
Using Laravel’s Str Helper
Laravel provides a Str helper, which is more flexible:
-
Lowercase using
Str::lower()
{{ \Illuminate\Support\Str::lower("Hello World") }} <!-- Output: hello world -->
- Uppercase using
Str::upper()
{{ \Illuminate\Support\Str::upper("Hello World") }} <!-- Output: HELLO WORLD -->
Using Inside Variables
If you are passing a variable from a controller:
{{ strtoupper($title) }} <!-- Convert title to uppercase -->
{{ strtolower($title) }} <!-- Convert title to lowercase -->
