Laravel 10 to_route() and str() helper function - NEW

20-Apr-2023

.

Admin

Laravel 10 to_route() and str() helper function - NEW

Hello Friends,

This tutorial is focused on Laravel 10 to_route() and str() helper function - NEW. we will help you to give example of laravel 10 redirect route from controller example. you can see laravel 10 to_route helper example. if you have question about laravel 10 to_route example then I will give simple example with solution.

Laravel 10 now comes with new str() helper function globally that you can use to do string operations fluently just like how you would do with Str::of.In addition to the str() helper, Laravel 10 also comes with a convenient to_route() helper function that you can use instead of redirect()->route() for named routes for instance.

So let's start with following examples:

Example: str() helper:


OLD Way with Str:

use Illuminate\Support\Str;

$input = 'this is test file.php';

$output = Str::of($input)

->replaceLast('php', 'html')

->camel();

// thisIsTestFile.html

New Way with srt() helper:

$input = 'this is test file.php';

$output = str($input)

->replaceLast('php', 'html')

->camel();

// thisIsTestFile.html

Example: to_route() helper:

OLD Way with Redirect:

Route::get('redirectHome', function() {

return redirect()->route('home');

});

New Way with to_route() helper:

Route::get('redirectHome', function() {

return to_route('home');

});

now it works...

I hope it can help you...

#Laravel 10