Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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.

like image 777
Vranvs Avatar asked Jul 30 '18 14:07

Vranvs


People also ask

How does Laravel define route in blade?

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.

How can I know my route in Laravel?

You may use the current, currentRouteName, and currentRouteAction methods on the Route facade to access information about the route handling the incoming request: $route = Route::current(); $name = Route::currentRouteName(); $action = Route::currentRouteAction();

What is Route :: domain Laravel?

Route::domain (Used in Laravel 5.4)or Route::group(['domain' => 'xyz.com'])? are is used when you have a sub domain which can be either dynamic or statc for example. Copy Code. Route::domain('{account}. myapp.com')->group(function () { Route::get('user/{id}', function ($account, $id) { // }); });


3 Answers

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

like image 121
rkj Avatar answered Oct 20 '22 02:10

rkj


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');
like image 4
Nelson Katale Avatar answered Oct 20 '22 02:10

Nelson Katale


There is a possibility that you cashed the route so clear route cashe

php artisan route:clear

if you still not finding your route After clearing cache, then remove the route and re-write your route with different keywords, hope you will find the problem

like image 3
khatib Avatar answered Oct 20 '22 03:10

khatib