【发布时间】:2021-07-16 16:13:28
【问题描述】:
我有两张桌子 show_types 和场地。通过多对多关系,我确实创建了一个新的支点,如下所示
public function up()
{
Schema::create('show_types_venues', function (Blueprint $table) {
$table->integer('show_types_id')->unsigned();
$table->foreign('show_types_id')->references('id')->on('show_types');
$table->integer('venue_id')->unsigned();
$table->foreign('venue_id')->references('id')->on('venues');
});
}
并添加到模型中
ShowType.php
public function venues()
{
return $this->belongsToMany(Venue::class, 'show_types_venues', 'show_types_id', 'venue_id');
}
Venue.php
public function shows()
{
return $this->belongsToMany(ShowType::class, 'show_types_venues', 'venue_id', 'show_types_id');
}
我正在尝试使这种关系显示在 Nova 上使用
ShowType.php
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Name'),
BelongsToMany::make('Venues', 'venues', Venue::class)
];
但我的界面中没有显示任何内容。我怎样才能让它显示一个选择多个,我可以添加/编辑与此 showType 关联的场所? 我需要创建更多“手动”的东西吗?谢谢
【问题讨论】:
标签: laravel eloquent laravel-nova