I used this line of code to show next post title on my app
<span class="blog-title-next"> {{ $post->nextPost()['title'] }} </span>
How can I limit the title name to show only first 10 characters?
Thanks.
Just change the $your_string part with your actual string and also the 50 part with the number of characters that you would like to limit your string to.
In Laravel 4 & 5 (up to 5.7), you can use str_limit, which limits the number of characters in a string. While in Laravel 5.8 up, you can use the Str::limit helper.
You can use laravel helper method Str::length() to find string length or you can use php strlen() method .
You could use the str_limit()
helper function:
{{ str_limit($post->nextPost()['title'], 10) }}
For newer version of laravel
use Illuminate\Support\Str;
$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20, ' (...)');
// The quick brown fox (...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With