Error Crud update Laravel

3

Someone helps me with this error that has me already with a headache please

Part of the Controller of the Update:

 public function edit($id)
{
   return view("almacen.categoria.edit",["categoria"=>Categoria::findOrFail($id)]);

}
public function update(CategoriaFormRequest $request,$id)
{
    $categoria=Categoria::findOrFail($id);
    $categoria->nombre=$request->get('nombre');
    $categoria->descripcion=$request->get('descripcion');
    $categoria->update();
    return Redirect::to('almacen/categoria');
}

The View of the Update:

@extends ('layouts.admin')
@section ('contenido')
<div class="row">
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
        <h3>Editar Categoría: {{ $categoria->nombre}}</h3>
        @if (count($errors)>0)
        <div class="alert alert-danger">
            <ul>
            @foreach ($errors->all() as $error)
                <li>{{$error}}</li>
            @endforeach
            </ul>
        </div>
        @endif

        {!!Form::model($categoria,['method'=>'PATCH','route'=>['almacen.categoria.update',$categoria->idcategoria]])!!}
        {{Form::token()}}
        <div class="form-group">
            <label for="nombre">Nombre</label>
            <input type="text" name="nombre" class="form-control" value="{{$categoria->nombre}}" placeholder="Nombre...">
        </div>
        <div class="form-group">
            <label for="descripcion">Descripción</label>
            <input type="text" name="descripcion" class="form-control" value="{{$categoria->descripcion}}" placeholder="Descripción...">
        </div>
        <div class="form-group">
            <button class="btn btn-primary" type="submit">Guardar</button>
            <button class="btn btn-danger" type="reset">Cancelar</button>
        </div>

        {!!Form::close()!!}     

    </div>
</div>
@endsection

Image of the category table ...

    
asked by Javier 24.08.2018 в 17:17
source

2 answers

5

Your primary key is called idcategoria is not called id! Establish in the model:

protected $primaryKey = 'idcategoria'; 

Greetings

    
answered by 24.08.2018 / 17:49
source
-1

Dear change it by this value

{!!Form::model($categoria,['method'=>'PATCH','route'=>['categoria.update',$categoria->idcategoria]])!!}
    
answered by 18.11.2018 в 06:31