Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel String To Lower

Tags:

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?

like image 398
locnguyen Avatar asked Oct 05 '15 20:10

locnguyen


2 Answers

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.

like image 134
BrokenBinary Avatar answered Sep 30 '22 19:09

BrokenBinary


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); 
like image 28
Zeussi Avatar answered Sep 30 '22 19:09

Zeussi