2

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;

15
  • could you also show what code have you written in your blade file ? Mar 18, 2019 at 6:31
  • 1
    In your index.blade, try {{ \Illuminate\Support\Str::function() }} Mar 18, 2019 at 6:31
  • <td>{{Str::limit($page->description, 100)}}</td> Mar 18, 2019 at 6:33
  • Can you try <td>{{ \Str::limit($page->description, 100) }}</td> In your index blade.
    – ArtisanBay
    Mar 18, 2019 at 6:39
  • which version of laravel you are using, for 5.8 taylor has removed string and array classed from laravel
    – umefarooq
    Mar 18, 2019 at 6:40

3 Answers 3

4

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>
0
1

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.

1
  • That's nice, but how do you use the alias?
    – dbf
    Feb 6 at 19:36
0

I've used:

use Illuminate\Support\Str;

in my Controller and

<td>{{ Illuminate\Support\Str::limit($page->description, 35)}}</td>

in my page where I wanted to use limit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.