我有2个雄辩的模特:
/**
* Entities/Products.php
*/
use CrudTrait;
protected $fillable = [
'name', 'macronutrients_id',
];
public function macronutrients()
{
return $this->hasOne(Macronutrients::class);
}
/**
* Entities/Macronutrients.php
*/
use CrudTrait;
protected $fillable = [
'proteins', 'fats', 'carbons', 'calories', 'product_id'
];
public function product()
{
return $this->belongsTo(Product::class);
}
我不知道如何通过Laravel Backpack CRUD在产品的编辑页面上显示带有所有常量营养素的表格(或选项列表之类的东西)?
换句话说,我想做这样的事情:
第http://example.com/admin/product/2/edit页:
* [text] Name
* Macronutrients:
[number] proteins
[number] fats
[number] carbons
[number] calories
其中[文本],[数字]是输入字段。
答案 0 :(得分:0)
$this->crud->addColumn([
// 1-n relationship
'label' => "Country name", // Table column heading
'type' => "select",
'name' => 'country_name', // the column that contains the ID of that connected entity;
'entity' => 'country', // the method that defines the relationship in your Model
'attribute' => "country_name", // foreign key attribute that is shown to user
'model' => "App\Models\Country",
]);
这是laravel背包中1-n关系的一个例子