Truncate String Using Limit() In Laravel Blade

Hello Artisan, in this tutorial i will show you how we can truncates the given string in laravel. Sometimes we need to trancate string in our laravel blade file. Like our post body or page body text.

Laravel has awesome method like limit() to trancate string in laravel. The limit method truncates the given string to the specified length. So you can use it in your laravel app like below.

use Illuminate\Support\Str;

$truncated = Str::of('The quick brown fox jumps over the lazy dog')->limit(20);

// The quick brown fox...

 

You may also pass a second argument to change the string that will be appended to the end of the truncated string:

use Illuminate\Support\Str;

$truncated = Str::of('The quick brown fox jumps over the lazy dog')->limit(20, ' (...)');

// The quick brown fox (...)

 

Hope it can help you.

 

#laravel #laravel-helper #limit #str