Laravel 'Route Not Defined' when route is clearly defined
I'm remaking the registration for my site, and have made a form that takes e-mail, password etc:
<form method="POST" class="etc" action="{{ route('register/blade/create') }}">
...
</form>
Then of course, my submit button in the form submits it and from routes in web.php:
Route::post('/register/basic/create', 'RegisterController@create');
However, every time I load this page, I get the following error:
I tried following others who had similar problems that posted on stack overflow, creating a named route, but that didn't seem to do the trick either. Any help is appreciated.
Solution 1:
When you use named route route
then you have to specify routes name in your routes/web.php
file. Like this
routes/web.php
Route::post('/register/basic/create', 'RegisterController@create')->name('register');
In blade file
<form method="POST" class="etc" action="{{ route('register') }}">
...
</form>
Check details here https://laravel.com/docs/5.6/routing#named-routes
Solution 2:
Sometimes the above error occurs when you have two routes with the same uri but different callbacks and different route name
For example
Route::post('update','PermissionController@update')->name('update_permission');`
Route::post('update','RoleController@update')->name('update_role');
The above routes update different resources but it will still return an error Route update_permission
not defined or Route update_role
not defined.
So the best thing to do is to use a different uri in each route so as to prevent conflict like this
Route::post('/role_permission/update','RoleController@update')->name('update_role');`
Route::post('/permission/update','PermissionController@update')->name('update_permission');
Solution 3:
If still it is not working and you checked every thing carefully then there is a possibility that you cashed the route so clear route cashe
php artisan route:clear