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;
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>
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.
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.
{{ \Illuminate\Support\Str::function() }}