It looks like there is no need to answer the question but regarding the situation here, you are trying an excerpt like content from a field, which means you want to grab only 141
characters from body
field and while this would work but you have to tweak it because LEFT
function would return exactly 141
characters and it could be ended up (the last character) in the middle of a word like hel...
where the word is hello
and 141th
character is l
so it needs to be a complete word to show an excerpt and Laravel
has built-in solution for this, using Str::words()
method you can specify how many complete words to show so I think, you may use this as well:
Str::words($post->body, 30); // show first 30 words from the $post->body
Default is: words($value, $words = 100, $end = '...')
Str::words($post->body)
This will output, first 100
complete words from any text and it'll end with ...
, so, for example, if the hello
is the last word then it'll ended like hello...
.