guys i have a problem when passing two parameters in the url that is in fileweb.php
I used
Route::resource('/exams/{exam}/questions', 'Backend\QuestionController');
to define the default routes.
In the terminal looks like:
| | PUT|PATCH | exams/{exam}/questions/{question} | questions.update | App\Http\Controllers\Backend\QuestionController@update | web |
| | | | | | auth |
| | DELETE | exams/{exam}/questions/{question} | questions.destroy | App\Http\Controllers\Backend\QuestionController@destroy | web |
| | | | | | auth |
| | GET|HEAD | exams/{exam}/questions/{question}/edit | questions.edit | App\Http\Controllers\Backend\QuestionController@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 theController.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>
| | PUT|PATCH | exams/{exam}/questions/{question} | questions.update | App\Http\Controllers\Backend\QuestionController@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 ]) }}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.