Issue
Hello i am trying to change 2 values from a table in DB, using Laravel 8, but for some reason, when i press the button to update my data, i get a 404 not found. However i have the route defined, and it appears on the list when i use php artisan routes:list I also tried clearing all cache , and it still doesn't work
My controller
public function confirmar_pedido_mentoria(Request $request){
$user = User::findOrFail($request->mentorando_id);
$user -> area_interesse = $request->area_interesse;
$user -> pedido_mentoria = 1;
$user -> update();
return redirect('/admin/pedido_mentoria/{{$user->id}}')->with('msg', 'Pedido realizado com sucesso!');
}
My routes
Route::get('/admin/pedido_mentoria/{id}', [UsersController::class, 'pedido_mentoria'])->middleware('auth');
Route::put('/admin/confirmar_pedido/{id}', [UsersController::class, 'confirmar_pedido_mentoria'])->middleware('auth');
I put here the get route, because that is the route i intend to user when i redirect after updating the values
My blade view
<?php
$inter = $user->interesses->pluck('id')->toArray();
?>
<h1 style="font-family: Eczar">Efectuar Pedido de Nova Mentoria: {{$user->user}}</h1>
<div class="col-md-6 offset-md-3">
<form action="/admin/confirmar_pedido/{{$user->id}}" method="POST" enctype="multipart/form-data" name="Form" onsubmit="return validateForm()">
@csrf
@method('PUT')
<div class="form-group">
<p style="font-family: Eczar">Escolha a Área de Interesse</p>
<div class="form-group">
@foreach($interesses as $interesse)
<input type="radio" name="area_interesse[]" class="area_interesse" value="{{$interesse->id}}" @if (in_array($interesse->id, $inter)) checked="checked" @endif > {{$interesse->area_interesse}} <br/>
@endforeach
</div>
<input type="submit" class="btn btn-primary" value="Escolher">
</form>
</div>
Solution
You have to get your id parameter in controller function(confirmar_pedido_mentoria). Edit your code :
public function confirmar_pedido_mentoria(Request $request,$id){
....
}
Answered By - MH Malekian
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.