Laravel string to drop

I am trying to convert a string to lowercase into 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 need to import the Illuminate\Support\Str class into a specific file?

+13
php laravel laravel-5
source share
3 answers

Why not just use the strtolower built in PHP?

 <img src="images/{{ strtolower($matchup->visitorTeam) }}sml.jpg"> 

Or, if you need full support for UTF-8, you can use mb_strtolower($string, 'UTF-8') which allows you to use umlauts and other fun things of UTF-8. This is what the Laravel Str::lower() function does.

+25
source share

Because in the comments that you asked yet, how it works in the Laravel method, so here is an alternative solution next to strtolower and mb_strtolower , which also works great.

You must add namsepace before the method so that PHP and Laravel can find this 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 need to add a namespace where Str is on top:

 use Illuminate\Support\Str; 

After that, you can call it without a namespace prefix:

 Str::lower($test); 
+10
source share

Consider using mb_strtolower to be able to convert any character that has the alphabet property, such as ฤŒ, ฤ† , etc.

0
source share

All Articles