首先,示例表:
产品:
- id <
- 名称/gh>价格
优惠:
- product_id (to Products id foreign)
- old_price
- new_price
我应该使用什么类型的字段来获取之前选择的外部项目的价格?对old_price的价格值
选择产品的字段:
$this->crud->addField([
'label' => 'Product',
'type' => 'select',
'name' => 'product_id',
'entity' => 'products',
'attribute' => 'name',
//'model' => "BackpackProductsappModelsProducts",
]);
Promos模型函数:
public function products()
{
return $this->belongsTo(Products::class,'product_id','id');
}
我试图使用一个select2_ajax,但我得到了一个路由问题(错误404)。
由于促销活动至少有一个产品,您可以使用模型的确切名称空间指定type relationship。
$this->crud->addField([
'label' => 'Product',
'type' => 'relationship',
'name' => 'product_id',
'entity' => 'products',
'attribute' => 'name',
'model' => 'BackpackProductsappModelsProducts',
]);