【发布时间】:2019-06-13 10:01:16
【问题描述】:
我有什么:
数据库中的表:
Schema::create('orders', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('primary_person');
$table->unsignedBigInteger('secondary_person');
});
Schema::create('persons', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('first_name', 255);
$table->string('last_name', 255);
});
型号:
class Order extends Model
{
use CrudTrait;
protected $table = 'orders';
protected $fillable = [
'primary_person',
'secondary_person',
];
public function primaryPerson()
{
return $this->hasOne(Person::class, 'id', 'primary_person');
}
public function secondaryPerson()
{
return $this->hasOne(Person::class, 'id', 'secondary_person');
}
}
需要做什么:
在页面编辑订单我想显示两个人的信息:
- 主要人员的名字
- 主要人员的姓氏
- 次要人员的名字
- 第二个人的姓氏
我做了什么:
在 OrderCrudController.php 中添加:
$this->crud->addFields([
[
'label' => 'First Name of Primary person',
'type' => 'text',
'name' => 'first_name',
'entity' => 'primaryPerson',
'model' => 'App\Models\Person',
],
[
'label' => 'Last Name of Primary person',
'type' => 'text',
'name' => 'last_name',
'entity' => 'primaryPerson',
'model' => 'App\Models\Person',
],
[
'label' => 'First Name of Secondary person',
'type' => 'text',
'name' => 'first_name',
'entity' => 'secondaryPerson',
'model' => 'App\Models\Person',
],
[
'label' => 'Last Name of Secondary person',
'type' => 'text',
'name' => 'last_name',
'entity' => 'secondaryPerson',
'model' => 'App\Models\Person',
]
]);
我收到了什么:
只有最新的两个字段(第二个人信息)。
我想看什么
主要问题:
我无法显示具有相同 "name" 的字段,因为 "name" - 属性(数据库中的列),它也将成为名称输入。
在列中,这种情况使用 "key" 属性处理。 但在 Fields 中它不起作用。
【问题讨论】:
标签: php laravel crud laravel-backpack