10-Apr-2023
.
Admin
Hello Friends,
This article is focused on Laravel 9 to_route() and str() helper function - NEW. you can understand a concept of laravel 9 to_route example. if you want to see example of laravel 9 to_route helper example then you are a right place. let’s discuss about laravel 9 str helper function. You just need to some step to done laravel 9 to_route() and str() helper function.
Laravel 9 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 9 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