我正在尝试更新管理员的某些表的行 . 它背着背包运行 . 我正在做一些调试,我在背包CrudController(vendor / backpack / crud / src / app / http / controllers / crudController - UpdateCrud函数)中结束这句话 .
$request->get($this->crud->model->getKeyName();
当我在它上面使用dd()时,它给了我一个空值 . 因此,最终结果显示404错误说“没有查询结果模型['模型路线']' . 此外,我打印更新请求和每个字段它没关系,发送数据没有问题 .
我花了6天时间试图解决这个问题但找不到它 . 这是我的代码的一部分,感谢您的时间 .
控制器(我恢复了一些领域,因为很多)
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');
}
}
1 回答
在
EntityCrudController::update()
方法中,您应该能够在调用parent::updateCrud()
后使用$this->crud->entry
. 所以这应该适合您获取当前条目ID: