2

I am trying to use Laravel 5.2's RESTful resource controllers. However, when moving from my index to create, I would like to pass a parameter as the create page should be partially filled in.

edit The form that will be 'created' will have populated fields from the database already. So the create should take the id from the user that is clicked in the index.

My temporary solution:

Route::get('consultation/{id}', 'ConsultationController@create');
Route::resource('consultation', 'ConsultationController', ['except' => ['create']]);

Is there a way to add this to an options array in the same line as resource?

Thanks

Edit: I suppose in this case, my store would also need the same {id} parameter.

3
  • sorry but i dont get what you mean, you want to pass something from the view to be shown in the create view? from where you will get it? user input in index or what? can you explain better please Commented May 9, 2016 at 2:27
  • I edited my post. The info will be pulled from the database based on the id being passed in. I have an index with clickable rows, when that row is clicked, it should redirect to the create resource but pass in an id, by default Laravel's RESTful controller has create with no parameters. Commented May 9, 2016 at 2:34
  • you can use a form in the index with a methd=get with a hidden input instead of <a> and then access the data via $request->input('') in the @create function and return it with it Commented May 9, 2016 at 2:38

1 Answer 1

4

I was also curious about that but I think that the Laravel Documentation is pretty clear about this:

If it becomes necessary to add additional routes to a resource controller beyond the default resource routes, you should define those routes before your call to Route::resource

And they add the following, meaning for me that if you want to override a defined route, you just need to put the definition on top of the Route::resource() definition.

otherwise, the routes defined by the resource method may unintentionally take precedence over your supplemental routes

EDIT

After better understanding the question, I would let the restful controller as is, and create a new route like /user/{user-id}/consultations/create that is much more "restful" like.

Sign up to request clarification or add additional context in comments.

5 Comments

The reason I do not want to use the show() method is because I would like the create to be partially filled in based on the {id}, and the rest be filled in by the user. Where as I would like show() to be the fully filled out form. Thank you for the answer, I will probably just keep it above the resource() definition.
I understand your point, but if you use consultation/{id} as a route, this will override your show() method, am I wrong? You could create a route like consultation/create/{id} or something
You are right. I'll change my route to that. Thanks
Ho, and if this is a user id, I would rather make a route like: /user/{user-id}/consultations/create that is, in my opinion much more "restful"
I'll take that into consideration - overall structure is a bit messy at the moment ha. Thanks again.

Your Answer

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.