Skip to content
Advertisement

Missing required parameters for [Route: questions.update] pass 2 parameters in the url

guys i have a problem when passing two parameters in the url that is in file web.php

That’s my error

I used

Route::resource('/exams/{exam}/questions', 'BackendQuestionController');

to define the default routes.

In the terminal looks like:

|        | PUT|PATCH | exams/{exam}/questions/{question}      | questions.update   | AppHttpControllersBackendQuestionController@update                 | web        |
|        |           |                                        |                    |                                                                        | auth       |
|        | DELETE    | exams/{exam}/questions/{question}      | questions.destroy  | AppHttpControllersBackendQuestionController@destroy                | web        |
|        |           |                                        |                    |                                                                        | auth       |
|        | GET|HEAD  | exams/{exam}/questions/{question}/edit | questions.edit     | AppHttpControllersBackendQuestionController@edit                   | web        |
|        |           |                                        |                    |                                                                        | auth       |

And to redirect, it is written this way

<a href="{{ route('questions.edit', [ $exams->id, $question->id ]) }}"class="btn btn-warning btn-sm"><i class="far fa-edit"></i></a>

And the Controller.php

 public function edit(Exam $exams, Question $questions, Category $category){
        return view('question.edit', compact( 'exams' ,'questions', 'category'));
    }

    public function update(QuestionUpdateRequest $request, $id){
        $questions = Question::find($id);
        $questions->description = $request->get('description');
        $questions->iframe = $request->get('iframe');
        $questions->image = $request->get('image');

        $questions->exam_id = $request->get('exam_id');
        $questions->category_id = $request->get('category_id');
        $questions->save();
        return redirect()->route('question.index', $questions->exam_id);
    }

But I can’t understand why it fails, if I’m already passing the parameters indicated by the url.

Also add the edit view

<form action="{{ route('questions.update', $questions->id ) }}" method="POST" enctype="multipart/form-data">
   {{--/exams/{{$exams->id}}/questions--}}
    <div class="form-group">
        {{--<input type="hidden" name="question_id" value="{{$questions->id}}">--}}
        <label for="description">Descripcion de la pregunta*</label>
        <textarea name="description" type="text"
                  class="form-control" id="description"
                  aria-describedby="descriptionHelp"
                  placeholder="Inserte la pregunta">{{ old('description', $questions->description) }}</textarea>
        <small id="descriptionHelp"
               class="form-text text-muted">Escribe la descripcion de la pregunta.</small>
    </div>
    <div class="form-group">
        <label for="iframe">Video asociado *</label>
        <textarea name="iframe" type="text"
                  class="form-control" id="iframe"
                  aria-describedby="iframeHelp"
                  placeholder="Inserte la URL del video">{{ old('iframe', $questions->iframe) }}</textarea>
        <small id="iframeHelp" class="form-text text-muted">Inserta la url del video.</small>
    </div>

    <div class="form-group d-flex flex-column">
        <label for="image">Imagen asociada</label>
        <input name="image" type="file" class="py-1">
    </div>
    <div class="form-group">
        <label for="category">A que categoria pertenece</label>
        <select name="category_id" class="form-control form-control-lg" id="category_id">
            @foreach($category as $category)
                <option value="{{ $category->id }}">{{ $category->name }}</option>
            @endforeach
        </select>
        <small id="selectHelp" class="form-text text-muted">Elige una categoria.</small>
    </div>
    <hr />
    @CSRF
    @method('PUT')
    <button type="submit" class="btn btn-primary">Guardar pregunta</button>
</form>

Advertisement

Answer

|        | PUT|PATCH | exams/{exam}/questions/{question}      | questions.update   | AppHttpControllersBackendQuestionController@update                 | web        |

that is your route but,

<form action="{{ route('questions.update', $questions->id ) }}" method="POST" enctype="multipart/form-data">

this is your action. You are missing the exam id in form action.

it should be

{{ route('questions.update', [ $exams->id, $question->id ]) }}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement