There are many different ways to limit the length of a string. For example, you could use CSS, JavaScript, or do it through PHP.
Laravel also provides a nice helper to make this easy! We will be using the Str
class from Illuminate\Support\Str
namespace.
In order to limit the length of a string directly in your blade files, you can use the following:
<p>
{{ Str::limit($your_string, 50) }}
</p>
You don’t have to import the namespace as this is a global “helper” PHP function available out of the box with Laravel.
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.
#laravel #php #developer