Support the ongoing development of →
Forms Laravel Requests
Last updated 1 year ago.

If I misunderstood question then pardon.

If you need ID of the question in controller after submission, Then

  1. Get ID separately in route: i.e
     Route::post('/save-answer/{question_id}, 'Controller@function_name');
  1. In controller, receive it as second parameter


 public function function_name(Request $request, $question_id){

 //validate everything in request

 $question = Question::find($question_id);



  1. In the View, give the form complete url with question id, i.e


 <form action="{{ url('save-answer/'. $question->id) }}" class="submit_answer">
      <!--token and all other inputs-->


  1. On submit in ajax just get form action for each question and send post request on route, i.e


 $('.submit_answer').on('submit', function(e){
      url: $(this).attr('action'), //get action attribute of the submitting form
      data: $(this).serialize(),
      type: 'post',
      success: function(result){
           //Do whatever you want to do here..
      error: function(errors){
           console.log(errors); //These are your laravel validation errors


Last updated 5 years ago.

Sign in to participate in this thread!


Your banner here too?

unixlike peronstevens Joined 30 Dec 2018


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.