How to Limit Words not Characters in Laravel
In this lesson, we are going to see how to limit words not characters in Laravel, the words helper method is used to limit the number of words in a string.
The Str::words helper method
The words() method is used to limit the number of words in a string, you can add a third argument to append a string to the end of the truncated string.
use Illuminate\Support\Str;
$paragraph = Str::words('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid, nemo.', 6, '...');
echo $paragraph; //
Returns "Lorem ipsum dolor sit amet, consectetur..."