PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 21, 2022

[FIXED] 404 Not Found but Route is defined Laravel

 February 21, 2022     laravel, laravel-blade, routes     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing