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>
Advertisement
Answer
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 IlluminateSupportStr;
Ref:https://laravel.com/docs/8.x/helpers#method-str-words
you can avoid use import like below
{{IlluminateSupportStr::words($UseCase->translate($lang)->description, 20, ' (...)')}}