Laravel 5 route not defined, while it is?
The route()
method, which is called when you do ['route' => 'someroute']
in a form opening, wants what's called a named route. You give a route a name like this:
Route::patch('/preferences/{id}',[
'as' => 'user.preferences.update',
'uses' => 'UserController@update'
]);
That is, you make the second argument of the route into an array, where you specify both the route name (the as
), and also what to do when the route is hit (the uses
).
Then, when you open the form, you call the route:
{!! Form::model(Auth::user(), [
'method' => 'PATCH',
'route' => ['user.preferences.update', Auth::user()->id]
]) !!}
Now, for a route without parameters, you could just do 'route' => 'routename'
, but since you have a parameter, you make an array instead and supply the parameters in order.
All that said, since you appear to be updating the current user's preferences, I would advise you to let the handling controller check the id of the currently logged-in user, and base the updating on that - there's no need to send in the id in the url and the route unless your users should need to update the preferences of other users as well. :)
This thread is old but was the first one to come up so I thought id share my solution too. Apart from having named routes in your routes.php file. This error can also occur when you have duplicate URLs in your routes file, but with different names, the error can be misleading in this scenario. Example
Route::any('official/form/reject-form', 'FormStatus@rejectForm')->name('reject-form');
Route::any('official/form/accept-form', 'FormStatus@acceptForm')->name('accept-form');
Changing one of the names solves the problem. Copy pasting and fatigue will get you to this problem :).
If route is not defined, then check web.php routing file.
Route::get('/map', 'NavigationController@map')->name('map'); // note the name() method.
Then you can use this method in the views:
<a class="nav-link" href="{{ route('map') }}">{{ __('Map') }}</a>
PS: the __('Map') is to translate "Map" to the current language.
And the list of names for routes you can see with artisan command:
php artisan route:list