Show excerpt from blog with Laravel

I am trying to show excerptsfrom blog posts. I can do this with phpand mysql. However, I am wondering if there is a more “friendly” way to do this within Laravel.

Thanks!

+4
source share
2 answers

You can do this using the method words

Default:

 words($value,$words = 100, $end='...');

You can implement it this way

Str::words($post->body);

Str::words($post->body,10); //will show first 10 words
+7
source

You can easily use str_limit.

Inside the PHP files:

str_limit($value, $limit = 100, $end = '...')

Inside Blade Templates files:

{{ str_limit($value, $limit = 100, $end = '...') }}

I saw that it is available from version 4.2 to 5.6

Link

0
source

All Articles