Laravel7 comes with a new Stringable class, which is useful in so many cool ways.

Previously, we’re familiar with Laravel’s existing Illuminate\Support\Str class, which provides a variety of helpful string manipulation functions but now Laravel7 offers a more object-oriented, fluent string manipulation library built on top of these functions.

We can still use the Laravel’s Str class, and modify whatever string we want to, likeso,

return (string) Str::of('  Laravel 6.x is Awesome ')
                    ->trim()
                    ->replace('6.x', '7.x')
                    ->slug();
//laravel-7.x-is-awesome

Let’s take a look at another example.

return (string) Str::of('Hello world')

                    ->title()

                    ->start('Devpeel ')

                    ->slug('_');
//Devpeel_Hello_world

For more information on the methods available via fluent string manipulation, please consult its full documentation.

You may also Like