Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
Tutorial Free

Laravel 5.1.11 introduces ACL system

August 31, 2015
2 min read
Another great news for Laravel community - more and more often repeated functions become a part of Laravel framework itself. Today a new addition is Authorization or ACL functionality. As usual, it was officially announced on Twitter - like this: Already retweeted and favorited by hundreds of Laravel fans, this feature adds some new functionality to Auth mechanism. Here are just a few example from new official documentation: New Gate facade:
if (Gate::forUser($user)->allows('update-post', $post)) {
    //
}
Using User model in request:
if ($request->user()->can('update-post', $post)) {
  // ... Update post
}
Blade helpers:
@can('update-post', $post)
    Edit Post
@endcan
Form Request classes - in method authorize():
return Gate::allows('update', Post::findOrFail($postId));
Wrapping rules into Policy classes: Artisan command:
php artisan make:policy PostPolicy
Policy Class function:
class PostPolicy
{
    public function update(User $user, Post $post)
    {
        return $user->id === $post->user_id;
    }
}
Personally, it reminds me a little of WordPress users/capabilities functions like current_user_can() and similar ones. Important note - this new functionality was built not only by Taylor Otwell himself, but also by Adam Wathan - thanks for that, guys!

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.