How to Truncate String in Laravel
BY: DA PUBLISHED: 2024-03-31 16:09:25 | UPDATED: 2025-10-11 17:30:04 | Views: 836
To truncate string in Laravel. Laravel 7

Laravel 7 offers a more object-oriented, fluent string manipulation library built on top
of Illuminate\Support\Str functions. Let’s see a few examples:
Table of contents
Truncate in controller
Using limit function, we can remove characters from string:
use Illuminate\Support\Str; $truncated = Str::of('The quick brown fox jumps over the lazy dog.')->limit(20); dd($truncated); // The quick brown fox...
We can replace … with any custom character. Let’s replace ... with >>>
use Illuminate\Support\Str; $truncated = Str::of('The quick brown fox jumps over the lazy dog.')->limit(20, ' >>>'); dd($truncated); // The quick brown fox >>>
We can also truncate words with words method:
use Illuminate\Support\Str; $truncated = Str::of('The quick brown fox jumps over the lazy dog.')->words(4); dd($truncated); // The quick brown fox...
Truncate in Blade
Remove characters from string in blade:
{!! Str::limit('The quick brown fox jumps over the lazy dog.', 20) !!} <!--The quick brown fox...-->
Truncate words in blade:
{!! Str::words('The quick brown fox jumps over the lazy dog.', 4) !!} <!--The quick brown fox...-->
If we want, we can set namespace too:
{!! \Illuminate\Support\Str::words('The quick brown fox jumps over the lazy dog.', 4) !!} <!--The quick brown fox...-->
That’s all, artisans. Thanks for reading.
You May Also Like

5G: What It Means for You
1 year agoLatest Videos
Sea waves & beach drone video
Jun 21, 2025Related Articles

The Future of AI in the IT Industry: Tra...
1 year ago
5G: What It Means for You
1 year ago