PHPackages                             flixtechs-labs/laravel-authorizer - 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. [Database &amp; ORM](/categories/database)
4. /
5. flixtechs-labs/laravel-authorizer

ActiveLibrary[Database &amp; ORM](/categories/database)

flixtechs-labs/laravel-authorizer
=================================

Implement robust laravel authorization logic without writing a single line of code

0.2.1(10mo ago)359914[4 PRs](https://github.com/flixtechs-labs/laravel-authorizer/pulls)MITPHPPHP ^8.1|^8.3CI passing

Since Aug 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/flixtechs-labs/laravel-authorizer)[ Packagist](https://packagist.org/packages/flixtechs-labs/laravel-authorizer)[ Docs](https://github.com/flixtechs-labs/laravel-authorizer)[ RSS](/packages/flixtechs-labs-laravel-authorizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (19)Used By (0)

Implement robust laravel authorization logic without writing a single line of code
==================================================================================

[](#implement-robust-laravel-authorization-logic-without-writing-a-single-line-of-code)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a8b951126a963625c06b0835f9f8d7b1f6b28784961c93ea336d82d3d197719e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666c697874656368732d6c6162732f6c61726176656c2d617574686f72697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/flixtechs-labs/laravel-authorizer)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8120b053a2ea11eccaa53e21912598b89d2d471df3e86f898e62c6320476cc75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f666c697874656368732d6c6162732f6c61726176656c2d617574686f72697a65722f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/flixtechs-labs/laravel-authorizer/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/16e65b7d46c8ac6ade35d863c096f738da3a3259040a46fe61302b830467dd8a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f666c697874656368732d6c6162732f6c61726176656c2d617574686f72697a65722f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/flixtechs-labs/laravel-authorizer/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/9660d812fb657a8c6f6f8371462d8c47604e0166a28f8ef9e2dada1a86f88d89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666c697874656368732d6c6162732f6c61726176656c2d617574686f72697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/flixtechs-labs/laravel-authorizer)

This package helps you to quickly create strong policy authorization logic in your Laravel application with minimal effort. In most cases the defaults will be just enough and all you'd need to do is authorize.

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

[](#installation)

You can install the package via composer:

```
composer require flixtechs-labs/laravel-authorizer
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-authorizer-config"
```

This is the contents of the published config file:

```
return [
    'permissions' => [
        'create',
        'update',
        'delete',
        'view all',
        'view',
        'force delete',
        'restore',
    ],
];
```

Setup
-----

[](#setup)

This package depends on the [spatie/laravel-permission](https://github.com/spatie/laravel-permission) package. It's installed automatically when you install this package.

To setup the package all you need to is run the following command:

```
php artisan authorizer:setup
```

If your project is ready you can generate the permissions on setup by adding the `--permissions` option:

```
php artisan authorizer:setup --permissions
```

You can also generate the policies on setup by adding the `--policies` option:

```
php artisan authorizer:setup --policies
```

Or you can generate both on setup by adding the `--permissions` and `--policies` options:

```
php artisan authorizer:setup --permissions --policies
```

This will publish the migrations from the spatie/laravel-permission package, migrate the database and generate the permissions and policies.

Usage
-----

[](#usage)

This package generates a batteries included policy skeleton. You just have to generate a policy and authorize in your controllers.

### Generate a policy for one model

[](#generate-a-policy-for-one-model)

```
php artisan authorizer:policies:generate Post --model=Post
```

This will generate a `PostPolicy` in the `App\Policies\` namespace. The generated Policy would look something like this:

```
