当我们创建新FormRequest我们有方法对象授权请求的方法Laravel
public function authorize()
{
return 1;
}
我的问题是,我可以有东西在这里,从形式,任何雄辩的模型对象?
像
public function authorize(Posts $post)
?
我意识到可通过,例如在这里的读取请求的数据$this->content
但我可以在这里发送整个对象?
让我们asumme我们post
集合视图。
我有形式
如果我能有这样的事
<form method="post" action="{{ route('temat.post.like', $post) }}">
而且在这条路的控制方法public function post_like(LikePost $request)
然后在所谓class LikePost extends FormRequest
授权方法有这个$post
像public function authorize(Posts $post)
我不知道是否有可能在授权方法中得到它,我寻找这个,我不认为这是可能的,但我可能是错的,这就是为什么我问
我的意思是有在这个authorize()
方法中,通过此参数获取的Eloquent Model就像控制器一样。
例如
public function authorize(Users $user)
网址:/like/15
通过ID 15
和方法,我们可以用它撷取的用户模型。
像
public function authorize(Users $user)
{
return $user->status;
}
其中$用户是用户雄辩型号
是授权在控制器的方法? 也许这就是你要找的https://laravel.com/docs/5.4/routing#route-model-binding –
@RafałŁyczkowski没有什么,我说,这是在请求 –