При использовании типа поля / столбца select2 в Laravel Backpack в представлении списка отображается «id» внешнего объекта вместо требуемого внешнего ключа (в данном случае «имя» сеанса).
Laravel 5.8.4, рюкзак 3.4. Я спросил в GitHub, и ответ был таков: мои отношения были неправильными в моих моделях. Я не думаю, что это проблема, поскольку имя загружается в режиме редактирования.
GradeCrudController
$this->crud->addColumn([
'label' => "Session",
'type' => 'select2',
'name' => 'session_id', // the db column for the foreign key
'entity' => 'session', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => "App\Models\Session" // foreign key model
]);
Оценка (модель)
public function session()
{
return $this->belongsTo('App\Models\Session');
}
Сессия (модель)
public function grades()
{
return $this->hasMany('App\Models\Grade');
}