0

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');
asked Feb 4, 2018 at 16:34
6
  • Please show how do you generate the link that shows 404. Commented Feb 4, 2018 at 16:35
  • The URL is: http://myapp.test/country/us/state/create just edited the post also Commented Feb 4, 2018 at 16:43
  • 1
    The create route should have precedence before the state route Commented Feb 4, 2018 at 16:46
  • @DaveyContreras thanks. As linktoahref said, put the create route before the first route. Commented Feb 4, 2018 at 16:47
  • Thanks you guys, That fixed the issue!!! and waoo... little things like that would have you pull your hairs... why does that even matter? Commented Feb 4, 2018 at 16:51

1 Answer 1

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.

answered Feb 4, 2018 at 17:03
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.