保存表单后,一旦我返回编辑,就不会保存我的选择选项。 我有两个模型PDA_Kategorije和PDA_Potkategorije。
class PDAPotkategorije extends Model
{ 使用CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'pda_potkategorije';
// protected $primaryKey = 'id';
// public $timestamps = false;
protected $guarded = ['id'];
protected $fillable = ['name', 'pdakategorija_id'];
// protected $hidden = [];
// protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
public function pda_kategorije()
{
return $this->hasOne('App\Models\PDAKategorije', 'id', 'pdakategorija_id');
}
PDAKategorije类扩展模型 { 使用CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'pda_kategorije';
// protected $primaryKey = 'id';
// public $timestamps = false;
protected $guarded = ['id'];
protected $fillable = ['name'];
// protected $hidden = [];
// protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
public function pda_potkategorije()
{
return $this->belongsTo('App\Models\PDAPotkategorije', 'pdakategorija_id', 'id');
}
在PDAPotkategorijeCrudController中,我有
$this->crud->addField([
'name' => 'name',
'type' => 'text',
]);
$this->crud->addField([
'label' => "Odaberite kategoriju",
'type' => 'select',
'name' => 'pdakategorija_id', // the relationship name in your Model
'entity' => 'pda_kategorije', // the relationship name in your Model
'attribute' => 'name', // attribute on Article that is shown to admin
'model' => "App\Models\PDAKategorije", //
]);
在setupListOperation中,将pda_potkategorije正确分配给pda_kategorije https://imgur.com/hA7rXO8
但是,一旦我单击“编辑”,pda_kategorije的选择选项就不会保存。