L o a d i n g
Laravel 9: New Helpers! BackEnd Development

Laravel 9: New Helpers!

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 (IlluminateSupportStringable). 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

Enter fullscreen mode Exit fullscreen mode

We should know, if no argument passed to this function it will give us a new instance of IlluminateSupportStr.

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']
);

Enter fullscreen mode Exit fullscreen mode

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 IlluminateSupportStr class.

Do your career a favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started