Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class Str not is missing but i dont know how to define it

Class 'Str' not found (View: C:\wamp\www\laravel\example\resources\views\pages\index.blade.php)

I have also tried

 use Illuminate\Support\Str;

& use Str;

like image 670
Deepak Singh Avatar asked Dec 31 '25 07:12

Deepak Singh


2 Answers

In Controller

namespace App\Http\Controllers;

class yourController extends Controller
{
   public method yourMethod() {

       $truncated = Illuminate\Support\Str::limit('The quick brown fox', 5); 
       dd($truncated);

   }
}

OR

You can also use Str like below also:

namespace App\Http\Controllers;

use Illuminate\Support\Str;

class yourController extends Controller
{
   public method yourMethod() {

       $truncated = Str::limit('The quick brown fox', 5); 
       dd($truncated);

   }
}

You can debug like above inside your controller file

Inside your blade file you use the Str helper function like below:

<td>{{ Illuminate\Support\Str::limit('The quick brown fox', 5) }}</td>
like image 60
ArtisanBay Avatar answered Jan 03 '26 04:01

ArtisanBay


For the Laravel Str class, you may add a line to the 'aliases' section into the config/app.php file

    'Str' => Illuminate\Support\Str::class,

then run

    composer dump-autoload

Restart the server.

like image 45
Kenny Kang Avatar answered Jan 03 '26 02:01

Kenny Kang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!