我已经注册了Comment
模型有一个User
参考,像这样:
public function user() {
return $this->belongsTo('App\User');
}
该函数返回一个实例User
,这是正确的,但我不知道如何注册User
列获取队列user
使用背包的属性。相反,我得到了模型的 JSON 表示形式:
So, 如何从关系函数中获取特定字段?
听上去像选择列 https://laravel-backpack.readme.io/docs/crud-columns-types#section-select非常适合您。只需在您的 EntityCrudController 中使用它setup()
方法,像这样:
$this->crud->addColumn([
// 1-n relationship
'label' => "User", // Table column heading
'type' => "select",
'name' => 'user_id', // the column that contains the ID of that connected entity;
'entity' => 'user', // the method that defines the relationship in your Model
'attribute' => "user", // foreign key attribute that is shown to user
'model' => "App\Models\User", // foreign key model
]);
“属性”告诉 CRUD 在表格单元格中显示什么(名称、id 等)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)