PHPackages                             cubekit/laracan - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. cubekit/laracan

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

cubekit/laracan
===============

Easy define abilities of the current user.

v0.2.1(11y ago)1125[2 issues](https://github.com/cubekit/laracan/issues)PHPPHP &gt;=5.4.0

Since Apr 2Pushed 11y ago2 watchersCompare

[ Source](https://github.com/cubekit/laracan)[ Packagist](https://packagist.org/packages/cubekit/laracan)[ RSS](/packages/cubekit-laracan/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

laracan
=======

[](#laracan)

Installation
------------

[](#installation)

- Require the package with composer:

`composer require cubekit/laracan`

- Add provider to your `config/app.php`:

```

	'providers' => [

	    // ...

        'Cubekit\Laracan\LaracanServiceProvider',

        // ...

	],

```

- Publish config:

`php artisan vendor:publish --provider="Cubekit\Laracan\LaracanServiceProvider"`

- Add the `Ability` class to the `app` folder and implement the `Cubekit\Laracan\AbilityContract`

> Note: the default config assumes that the `Ability` class is placed in the `app` folder. You are free to change it and place the class where would you want.

Usage
-----

[](#usage)

- Define abilities

```
class Ability implements AbilityContract {

    public function initialize($user, Closure $can)
    {
        $user = $user ?: new App\User;

        // NOTE: Laracan does not provide any roles behavior! Assume that some
        // package already installed for this, like Entrust
        if ($user->hasRole('admin')) {

            // Admin can edit posts and comments unconditionally
            $can('edit', 'Post');
            $can('edit', 'Comment');

            return;
        }

        // User can edit a post only if he is its author
        $can('edit', 'Post', ['author_id' => $user->getKey()]);

        $can('edit', 'Comment', function($comment) use ($user)
        {
            // User can edit a comment only if he is its author
            // and comment is not older than 15 minutes
            return (
                $comment->author_id == $user->getKey() &&
                $comment->created_at >= Carbon::now()->subMinutes(15)
            );
        });

    }
}
```

- Check ability in a request

```
class EditPostRequest {

    public function rules()
    {
        // ...
    }

    public function authorize()
    {
        $post = Post::find( $this->route('post') );

        return can('edit', $post);
    }

}
```

- Check ability in a view

```
@foreach($post->comments as $comment)

    {{ $comment->body }}

    @can('edit', $comment)

            Edit

    @endcan

@endforeach
```

- Or you can use the `can` function directly to force IDE understand this code

```
@foreach($post->comments as $comment)

    {{ $comment->body }}

    @if( can('edit', $comment) )

            Edit

    @endif

@endforeach
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

3

Last Release

4056d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0eb324fdbfae7d3ecaebad46b21cb61519b03f7abe5dbc047b9d210b5805b98f?d=identicon)[anatoliyarkhipov](/maintainers/anatoliyarkhipov)

---

Top Contributors

[![anatoliyarkhipov](https://avatars.githubusercontent.com/u/1934180?v=4)](https://github.com/anatoliyarkhipov "anatoliyarkhipov (13 commits)")

---

Tags

laravelpermissions

### Embed Badge

![Health badge](/badges/cubekit-laracan/health.svg)

```
[![Health](https://phpackages.com/badges/cubekit-laracan/health.svg)](https://phpackages.com/packages/cubekit-laracan)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[yajra/laravel-acl

Laravel ACL is a simple role, permission ACL for Laravel Framework.

112103.9k1](/packages/yajra-laravel-acl)[jurager/teams

Laravel package to manage team functionality and operate with user permissions.

22817.3k](/packages/jurager-teams)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)[beatswitch/lock-laravel

A Laravel Driver for Lock.

15529.1k1](/packages/beatswitch-lock-laravel)[klaravel/ntrust

Role-Based Permissions for Laravel 5.3+

10126.7k1](/packages/klaravel-ntrust)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
