I'm trying to convert a string to lowercase in a views page (index.blade.php)
The following is what I would like to achieve.
<img src="images/teamnamesml.jpg logo">
This is my attempt
<img src="images/{{ Str::lower($matchup->visitorTeam) }}sml.jpg">
I get this error
FatalErrorException in ed1bb29e73e623d0f837c841ed066275 line 71: Class 'Str' not found
Do I have to import the class Illuminate\Support\Str
to a specific file?
Why not just use the PHP built-in strtolower
?
<img src="images/{{ strtolower($matchup->visitorTeam) }}sml.jpg">
Or, if you need full UTF-8 support you can use mb_strtolower($string, 'UTF-8')
which allows umlauts and other fun UTF-8 stuff. This is what Laravel's Str::lower()
function does.
Because in the comments you asked still, how it works in the Laravel way, so here an alternative solution next to strtolower
and mb_strtolower
, which also work fine.
You have to add the namsepace in front of the method, that PHP and Laravel can find the method.
So, if you want to use it in Blade, do the following:
<img src="images/{{ Illuminate\Support\Str::lower($matchup->visitorTeam) }}sml.jpg">
If you want to use it in a Controller or Model, you have to add the namespace, where Str
is in on the top:
use Illuminate\Support\Str;
After that, you can call it without the namespace prefix:
Str::lower($test);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With