06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Authorization 240<br />

11 {<br />

12 /**<br />

13 * Update the given post.<br />

14 *<br />

15 * @param int $id<br />

16 * @return Response<br />

17 */<br />

18 public function update($id)<br />

19 {<br />

20 $post = Post::findOrFail($id);<br />

21<br />

22 if (Gate::denies('update', $post)) {<br />

23 abort(403);<br />

24 }<br />

25<br />

26 // Update Post...<br />

27 }<br />

28 }<br />

When checking policy methods that do not receive a model, such as a view method. You should pass<br />

the model name to the check method:<br />

1 Gate::check('view', Post::class);<br />

When a model class name is passed to the Gate instead of a model instance, the Gate will suffix the<br />

ability being checked with Any. So, in the example above, the Gate will call the viewAny method of<br />

the policy.<br />

Via The User Model<br />

The User model’s can and cannot methods will also automatically utilize policies when they are<br />

available for the given arguments. These methods provide a convenient way to authorize actions for<br />

any User instance retrieved by your application:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!