Skip to main content
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.

Recent Courses on Laravel Daily

Laravel 13 Eloquent: Expert Level

41 lessons
1 h 34 min

How to Build Laravel 13 API From Scratch

30 lessons
1 h 23 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read

No comments yet…