Home > Enterprise >  404 Not Found but Route is defined Laravel
404 Not Found but Route is defined Laravel

Time:01-17

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 >
        <form action="/admin/confirmar_pedido/{{$user->id}}" method="POST" enctype="multipart/form-data" name="Form" onsubmit="return validateForm()">
        @csrf
        @method('PUT')
        <div >
                
            <p style="font-family: Eczar">Escolha a Área de Interesse</p>
           
            <div >
           
            @foreach($interesses as $interesse)
           
             <input type="radio" name="area_interesse[]"  value="{{$interesse->id}}" @if (in_array($interesse->id, $inter)) checked="checked" @endif > {{$interesse->area_interesse}} <br/>
            @endforeach
        
           </div>
          
            <input type="submit"  value="Escolher">
            </form>
</div>

CodePudding user response:

You have to get your id parameter in controller function(confirmar_pedido_mentoria). Edit your code :

public function confirmar_pedido_mentoria(Request $request,$id){

        ....
    }  
  •  Tags:  
  • Related