Laravel 5.5 which is the different doing (no get and post methods) on route defintion web.php file:
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
regarding ->name('')
method
Is required define that method? in which cases?
(sample taked from Auth Class definition laravel)
The idea of defining ->name()
in routes is for easier code maintenance in the future, it's not mandatory.
Say for example you have few places which uses the route login
, one fine day you update the route to user-login
. You will have to find and update all the route being used, changing from url('login')
to url('user-login')
.
If you have a route name defined, you will be using route('login')
, when you update your route url, there's no need to update all the other files that you're using that route.
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