PHPackages                             roketin/astro - 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. roketin/astro

ActiveLibrary

roketin/astro
=============

This package provides a flexible way to add Role-based Permissions to Laravel

1.0.3(9y ago)068MITPHPPHP &gt;=5.4.0

Since Mar 21Pushed 9y ago5 watchersCompare

[ Source](https://github.com/roketin/astro)[ Packagist](https://packagist.org/packages/roketin/astro)[ RSS](/packages/roketin-astro/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

astro (Laravel 5 Package)
=========================

[](#astro-laravel-5-package)

[![Build Status](https://camo.githubusercontent.com/ab4bdc6b16b6cf8bdbe5878f4558bf379f6790048874eed907a798e113a26497/68747470733a2f2f7472617669732d63692e6f72672f726f6b6574696e2f617374726f2e737667)](https://travis-ci.org/roketin/astro)[![Version](https://camo.githubusercontent.com/f665bd5e5c9454c8ccd7497863415f039ee58cb4fdea0faefa5ff44cf708174d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6b6574696e2f617374726f2e737667)](https://packagist.org/packages/roketin/astro)[![License](https://camo.githubusercontent.com/043acb05af6498d5a4d90330ee9e10f4d7a0722220067ace14307ef0171655cf/68747470733a2f2f706f7365722e707567782e6f72672f726f6b6574696e2f617374726f2f6c6963656e73652e737667)](https://packagist.org/packages/roketin/astro)[![Total Downloads](https://camo.githubusercontent.com/fb27aa432b06b42663c9f639f4242d5892e76f8ab25b50c91a7e0313edc36faf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6b6574696e2f617374726f2e737667)](https://packagist.org/packages/roketin/astro)

[![SensioLabsInsight](https://camo.githubusercontent.com/0b1aa6bf92e58c3ebf1d5d2737f62dbbdc9b0f1f39190beb44d508e54933a386/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63633461663936362d383039622d346662632d623862322d6262323835306536373131652f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/cc4af966-809b-4fbc-b8b2-bb2850e6711e)

astro is a succinct and flexible way to add Role-based Permissions to **Laravel 5**.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Configuration](#configuration)
    - [User relation to roles](#user-relation-to-roles)
    - [Models](#models)
        - [Role](#role)
        - [Permission](#permission)
        - [User](#user)
        - [Soft Deleting](#soft-deleting)
- [Usage](#usage)
    - [Concepts](#concepts)
        - [Checking for Roles &amp; Permissions](#checking-for-roles--permissions)
        - [User ability](#user-ability)
    - [Blade templates](#blade-templates)
    - [Middleware](#middleware)
    - [Short syntax route filter](#short-syntax-route-filter)
    - [Route filter](#route-filter)
- [Troubleshooting](#troubleshooting)
- [License](#license)
- [Contribution guidelines](#contribution-guidelines)
- [Additional information](#additional-information)

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

[](#installation)

In order to install Laravel 5 astro, just add

```
"roketin/astro": "5.2.x-dev"

```

to your composer.json. Then run `composer install` or `composer update`.

Then in your `config/app.php` add

```
roketin\astro\astroServiceProvider::class

```

in the `providers` array and

```
'astro' => roketin\astro\astroFacade::class

```

to the `aliases` array.

If you are going to use [Middleware](#middleware) (requires Laravel 5.1 or later) you also need to add

```
    'role' => \roketin\astro\Middleware\astroRole::class,
    'permission' => \roketin\astro\Middleware\astroPermission::class,
    'ability' => \roketin\astro\Middleware\astroAbility::class,
```

to `routeMiddleware` array in `app/Http/Kernel.php`.

Configuration
-------------

[](#configuration)

Set the property values in the `config/auth.php`. These values will be used by astro to refer to the correct user table and model.

You can also publish the configuration for this package to further customize table names and model namespaces.
Just use `php artisan vendor:publish` and a `astro.php` file will be created in your app/config directory.

### User relation to roles

[](#user-relation-to-roles)

Now generate the astro migration:

```
php artisan astro:migration
```

It will generate the `_astro_setup_tables.php` migration. You may now run it with the artisan migrate command:

```
php artisan migrate
```

After the migration, four new tables will be present:

- `roles` — stores role records
- `permissions` — stores permission records
- `role_user` — stores [many-to-many](http://laravel.com/docs/4.2/eloquent#many-to-many) relations between roles and users
- `permission_role` — stores [many-to-many](http://laravel.com/docs/4.2/eloquent#many-to-many) relations between roles and permissions

### Models

[](#models)

#### Role

[](#role)

Create a Role model inside `app/models/Role.php` using the following example:

```
