Backpack for laravel - Error updating rows

118
June 26, 2018, at 9:10 PM

I'm trying to update rows of some tables on my admin. It's running with backpack crud. I've doing some debug and I'm ending on this sentence in backpack CrudController (vendor/backpack/crud/src/app/http/controllers/crudController - UpdateCrud function).

$request->get($this->crud->model->getKeyName();

It's giving me a null value when I use dd() on it. So the final result shows me a 404 Error saying 'No query results for model ['Model route']'. Also I print the update request and every field it's ok, sending data without problems.

I spend 6 days trying to resolve this problem and can't find it. This is part of my code, thanks for your time.

Controller (I resume some fields, because are to many)

class OperadoresCrudController extends CrudController {
  public function setup(){
    $this->crud->setModel('App\Models\Operador');
    $this->crud->setRoute("admin/operadores");
    $this->crud->setEntityNameStrings('operadores', 'operadores');
    $this->crud->enableExportButtons();
    /*
    |--------------------------------------------------------------------------
    | BASIC CRUD INFORMATION
    |--------------------------------------------------------------------------
    */
    //$this->crud->setFromDb();
    // ------ CRUD FIELDS
    // $this->crud->addField($options, 'update/create/both');
    // $this->crud->addFields($array_of_arrays, 'update/create/both');
    // $this->crud->removeField('name', 'update/create/both');
    // $this->crud->removeFields($array_of_names, 'update/create/both');
    $this->crud->addField([
      'name'  => 'nombre',
      'label' => 'Nombre *',
      'type'  => 'text',
      'wrapperAttributes' => [
        'class' => 'form-group col-md-7'
      ],
      'tab'  => 'Datos Generales'
    ]);
    $this->crud->addField([
      'name' =>  'rut',
      'label' => 'Rut',
      'type'  => 'text',
      'wrapperAttributes' => [
        'class' => 'form-group col-md-7'
      ],
      'tab'  => 'Datos Generales'
    ]);
    public function store(StoreRequest $request) {
      return parent::storeCrud();
    }
    public function update(UpdateRequest $request) {
      #dd($request);
      return parent::updateCrud();
    }
 }

Model

class Operador extends Model {
  use CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
  protected $table = 'operador';
  //protected $primaryKey = 'id';
  // public $timestamps = false;
  // protected $guarded = ['id'];
  protected $fillable = ['nombre','rut','direccion','telefono','email','comuna_id','url','region_id', 'area_operacion','op_nombre_responsable','op_direccion_responsable','op_telefono_responsable','op_email_responsable','created_at','updated_at'];
  // protected $hidden = [];
  // protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
  public function equipos() {
   return   $this->hasMany('App\Models\Equipo','operador_id');
  }
  public function comuna() {
    return $this->belongsTo('App\Models\Comuna');
  }
  //para insertar select region, prov, comuna
  public function region() {
    return $this->belongsTo('App\Models\Region');
  }
  // Estacion Operador.
  public function estaciones() {
    return $this->hasMany('App\Models\Estacion','operador_id');
  }
}
READ ALSO
How to get javascript value to PHP code? [duplicate]

How to get javascript value to PHP code? [duplicate]

This question already has an answer here:

97
PHP search in a variable text

PHP search in a variable text

I have this variable:

81
window is undefined in react server rendering

window is undefined in react server rendering

I'm using react and server side renderingWhen rendering my component I need access to window object as I need to know the width on the window

155