framadh
framadh

Reputation: 25

how to limiting word on the laravel blade?

I'm looking to find out how to limit word in laravel blade. I've coded using substr, but it's still not working properly. Can anyone help me?

<div class="description">
   {{ substr($UseCase->translate($lang)->description, 20).'...' }}
</div>

Upvotes: 1

Views: 2852

Answers (1)

John Lobo
John Lobo

Reputation: 15319

The Str::words method limits the number of words in a string. An additional string may be passed to this method via its third argument to specify which string should be appended to the end of the truncated string:

{{Str::words($UseCase->translate($lang)->description, 20, ' (...)')}}

you have to import

use Illuminate\Support\Str;

Ref:https://laravel.com/docs/8.x/helpers#method-str-words

you can avoid use import like below

 {{\Illuminate\Support\Str::words($UseCase->translate($lang)->description, 20, ' (...)')}}

Upvotes: 1

Related Questions