Soon, Laravel 9 wil release and there are some new features that we can use them.
This series is going to be a sequel about Laravel framework version 9 and in each article we will review a new feature!
1. str()
A new useful helper in Laravel 9 is str()
. This function will return a new Stringable
(Illuminate\Support\Stringable
). We had this method on Str
class and now it is more easier to use. eg:
$name = str('Reza')->append(' Khademi'); // 'Reza Khademi'
$snake = str()->snake('LaravelFramework'); // 'laravel_framework
We should know, if no argument passed to this function it will give us a new instance of Illuminate\Support\Str
.
2. to_route()
If we want to redirect user to a specific route, this will come handy:
return to_route(
'users.show',
['user' => 1],
302,
['X-Framework' => 'Laravel']
);
we can pass the route name as the first, our desired data as the second and additional response headers as the third and fourth arguments to the to_route()
method.
PHP 8 String Functions
Since PHP 8, str_contains()
, str_starts_with()
and str_ends_with()
functions moved in to the \Illuminate\Support\Str
class.
Top comments (0)