I am having issues getting the page to render when using a parameter in a create controller. My show controller works but my create controller doesn't. The error thrown is a 404.
Sorry, the page you are looking for could not be found.
The URL is:
http://myapp.test/country/us/state/create
My controller looks like:
// Show
public function show(Country $country, State $state){
return view('state.show', compact('state'));
}
// Create
public function create(Country $country) {
return view('state.create', compact('country'));
}
My route looks like:
Route::get('country/{country}/state/{state}', 'StateController@show');
Route::get('country/{country}/state/create', 'StateController@create');
1 Answer 1
You need to flip your routes around to be
Route::get('country/{country}/state/create', 'StateController@create');
Route::get('country/{country}/state/{state}', 'StateController@show');
Laravel processes routes in the order that they are defined, so in your current code Laravel was seeing create as a state.
Comments
Explore related questions
See similar questions with these tags.
http://myapp.test/country/us/state/createjust edited the post alsocreateroute before the first route.