Error in Laravel

1

I have the following error when editing a record NotFoundHttpException in RouteCollection.php line 161:  this is the code

Route::get('/ficha/editar/{id}', 'fichaController@editarficha');

Route::post('/ficha/edit/{id}', 'fichaController@editficha' );

in the controller

public function editarficha($id)
{

    $var = ficha::where('id', $id)->first();
    return view('edip',['var'=>$var]);


}


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

    $nuevoApellido=$request->input('apellido');
    $nuevoNombre=$request->input('nombre');
    $nuevoDNI=$request->input('dni');
    $nuevoEcivil=$request->input('ecivil');
    $nuevoNacional=$request->input('nacional');
    $nuevoFnaci=$request->input('fnaci');
    $nuevoEdad=$request->input('edad');
    $nuevoFingreso=$request->input('fingreso');

     $var= ficha::find($id);

          $var->apellido = $nuevoApellido;
          $var->nombre = $nuevoNombre;
          $var->dni = $nuevoDNI;
          $var->ecivil = $nuevoEcivil;
          $var->nacional = $nuevoNacional;
          $var->fnaci = $nuevoFnaci;
          $var->edad = $nuevoEdad;
          $var->fingreso = $nuevoFingreso;
          $var->save();
          return view('edip'); 



}

and the loading form

<form action="edit/{id}" method="post">

                {{ csrf_field() }}



                    <div class="col-md-6">

                       <div class="form-group"> 
                          <label for="nombre">Apellido</label> 
                          <input type="text" name="apellido" class="form-control" value="{{$var->apellido}} ">
                        </div>

                        <div class="form-group">
                          <label for="nombre">Nombre</label> 
                          <input type="text" name="nombre" class="form-control" value="{{$var->nombre}} ">
                        </div>

                        <div class="form-group">
                          <label for="nombre">D.N.I</label> 
                          <input type="text" name="dni" class="form-control" value="{{$var->dni}} ">
                        </div>

                        <div class="form-group">
                          <label for="nombre">Estado Civil</label> 
                          <input type="text" name="ecivil" class="form-control" value="{{$var->ecivil}} ">
                        </div>



                   </div>



                    <div class="col-md-6">

                       <div class="form-group"> 
                          <label for="nombre">Nacionalidad</label> 
                          <input type="text" name="nacional" class="form-control" value="{{$var->nacional}} ">
                        </div>

                        <div class="form-group">
                          <label for="nombre">Fecha de Nacimiento</label> 
                          <input type="text" name="fnaci" class="form-control" value="{{$var->fnaci}} ">
                        </div>

                        <div class="form-group">
                          <label for="nombre">Edad</label> 
                          <input type="text" name="edad" class="form-control" value="{{$var->edad}} ">
                        </div>

                        <div class="form-group">
                          <label for="nombre">Fecha Ingreso</label> 
                          <input type="text" name="fingreso" class="form-control" value="{{$var->fingreso}} ">
                        </div>






                   </div>
                   <div class="form-group text-right" > 
                          <button type="submit" class="btn btn-primary">Guardar</button>
                        </div> 

                   </form>
    
asked by leonaidass 28.07.2017 в 15:13
source

2 answers

1

Your error may be that in the form you are calling in action the path "edit / {id"

<form action="edit/{id}" method="post">

While in your route files you define it as Route :: post ('/ tab / edit / {id}', 'fichaController @ editficha');

Route::post('/ficha/edit/{id}', 'fichaController@editficha' );

Rehearse with that

    
answered by 28.07.2017 / 15:18
source
0

Check the name of the route for the action of the form, for this you can use the command

php artisan route:list

in case your route for some reason has no name and you can not call it

Route::get('/ficha/editar/{id}', 'fichaController@editarficha')->name('mi.ruta');
    
answered by 28.07.2017 в 20:04