模型 Question
和 Choice
之间的关系是多对多的 .
Nova/Question
:
public function fields(Request $request)
{
return [
...
BelongsToMany::make('Choices')
]
}
哪个显示在屏幕下方
我想从视图中隐藏视图和编辑选项 . 仅允许用户附加/分离选择 .
我尝试使用以下方法创建 QuestionPolicy
,但无效 . 如果我使用 ChoicePolicy
的 update
& create
方法,它将隐藏 Choice
资源中的查看和编辑选项 .
public function updateChoice(User $user, Question $question)
{
return false;
}
如何从关系中实现隐藏视图和编辑选项?
Update
Question
型号
class Question extends Model
{
...
/**
* The choices that belong to the question.
*/
public function choices()
{
return $this->belongsToMany('App\Choice');
}
}
Choice
型号
class Choice extends Model
{
/**
* The questions that belong to the choice.
*/
public function questions()
{
return $this->belongsToMany('App\Question');
}
}
3 回答
我认为您需要将以下代码放在QuestionPolicy中:
希望这有帮助 . https://nova.laravel.com/docs/1.0/resources/authorization.html#authorizing-attaching-detaching
希望对你有帮助
您可以在您的政策中退回此内容,同样适用于您的更新