As I understand from the Laravel documentation, it's used for redirection, but maybe I'm wrong.
I wrote
Route::get('user/profile', ['as' => 'profile', function () {
echo 'some_text';
}]);
then I was expecting my URL to redirect from
https://base_url/public/index.php/user/profile
to https://base_url/public/index.php/profile
but it doesn't happen.
Overall, I want to know, what the difference is if I used
Route::get('user/profile', function () {
echo 'some_text';
});
instead of the above routing rule.
The purpose isn't for re-direction in your routing file.
Instead, with the example route you provided, Laravel will allow you to reference said route by using:
$url = route('profile');
So you don't have to build the URL manually over and over again in your code.
So, in short: the difference is the first thing is a named route, and the last thing is a non-named route. Since you called the first route, you can reference it by that name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With