You have the option also to nest resources so that you would be posting your new question to /quizzes/42/questions. It's absent (AFAIK) from the 5.2 docs, but there is more here: https://laravel.com/docs/5.1/controllers#restful-nested-resources
Apr 9, 2016
2
Level 1
How to get the ID from the previous route/model
Hello, have 2 models:
- Quiz
- Question
When I am in the quiz.show I want to add a new question that belongs to a specific quiz. So assume I am at /quizzes/42 and then I click on an "add question" button, which has the route /questions/create. First I used a GET parameter but I wasn't sure if this is the best option. I switched to another approach where I set a session variable in my QuestionController@show action. But I'm still not very content with the approach.
I need some advice. Is there a best practice for this case? What's the most Laravel-like solution?
Best regards, Ctwx
Please or to participate in this conversation.