【发布时间】:2021-03-19 19:48:11
【问题描述】:
我有这个简单的动作:
/**
* Perform the action on the given models.
*
* @param \Laravel\Nova\Fields\ActionFields $fields
* @param \Illuminate\Support\Collection $models
* @return mixed
*/
public function handle(ActionFields $fields, Collection $models)
{
foreach ($models as $model) {
$model->update([
'user_id' => $fields->user
]);
}
}
/**
* Get the fields available on the action.
*
* @return array
*/
public function fields()
{
return [
BelongsTo::make('User', 'user', User::class),
];
}
起初,它似乎很好,但是当我从 BelongsTo 关系中选择用户并尝试保存时抛出异常:
Argument 1 passed to Laravel\Nova\Fields\BelongsTo::getRelationForeignKeyName() must be an instance of Illuminate\Database\Eloquent\Relations\Relation, instance of Illuminate\Support\Fluent given, called in /Users/rd/Sites/bns-crm/vendor/laravel/nova/src/Fields/BelongsTo.php on line 212
【问题讨论】:
标签: laravel laravel-nova