I'm trying to implement a basic authentication system using only the built-in Laravel features. The system works but only if I assign a name to the /admin/login route [i.e ...->name('admin.login)]. If I take it out, the exception I get is the following.
ErrorException (E_ERROR) Route [login.admin] not defined. (View: /var/www/html/shop/resources/views/auth/login.blade.php)
In the past, I have been able to visit unnamed routes, and I can visit other unnamed routes apart from the /login/admin
. I was hoping someone could tell me why I was getting the error.
Routes
Auth::routes();
Route::get('/login/admin', 'Auth\LoginController@showAdminLoginForm')->name('login.admin');
Route::get('/login/staff', 'Auth\LoginController@showStaffLoginForm');
Route::get('/register/admin', 'Auth\RegisterController@showAdminRegisterForm');
Route::get('/register/staff', 'Auth\RegisterController@showStaffRegisterForm');
The $url can have 2 values either admin or staff.
login blade page
@isset($url)
<form method="POST" action="{{ route('login.'.$url) }}">
@else
<form method="POST" action="{{ route('login') }}">
@endisset
The command routes:list
also shows that the route exists, just unnamed.
| | GET|HEAD | login/admin | | App\Http\Controllers\Auth\LoginController@showAdminLoginForm | web,guest,guest:admin,guest:staff |
| | POST | login/admin | | App\Http\Controllers\Auth\LoginController@adminLogin | web,guest,guest:admin,guest:staff |
| | GET|HEAD | login/writer | | App\Http\Controllers\Auth\LoginController@showWriterLoginForm | web,guest,guest:admin,guest:staff |
| | POST | login/writer | | App\Http\Controllers\Auth\LoginController@writerLogin | web,guest,guest:admin,guest:staff |
/login/admin
exist in your Auth::routes() as well? That could be overriding your named route. Or try placing your named route aboveAuth::routes()
– Cockatooadmin.login
"but only if I assign a name to the /admin/login route [i.e ...->name('admin.login)]," and then in your routes it islogin.admin
->name('login.admin');
? What's going on? – Leroylerwick