PHPackages                             edvinaskrucas/rbauth - 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. edvinaskrucas/rbauth

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

edvinaskrucas/rbauth
====================

8841PHP

Since Mar 30Pushed 13y ago1 watchersCompare

[ Source](https://github.com/edvinaskrucas/rbauth)[ Packagist](https://packagist.org/packages/edvinaskrucas/rbauth)[ RSS](/packages/edvinaskrucas-rbauth/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Simple Role Based Auth extension for Laravel 4
==============================================

[](#simple-role-based-auth-extension-for-laravel-4)

---

A simple Role/Permission based auth package for Laravel4

---

- Roles
- Permissions
- Exceptions
- Route filters

---

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

[](#installation)

Just place require new package for your laravel installation via composer.json

```
"edvinaskrucas/rbauth": "dev-master"

```

Then hit `composer update` after update you should migrate rbauth package by hitting `php artisan migrate --package=edvinaskrucas/rbauth`

### Registering it in Laravel

[](#registering-it-in-laravel)

Add following lines to `app/config/app.php`

ServiceProvider array

```
'Krucas\RBAuth\RBAuthServiceProvider'
```

Change auth driver to `rbauth` in `app/config/auth.php`

Now you are able to use it with Laravel4.

Config
------

[](#config)

If you want to use your own implementations of interfaces you need to publish package config file by using `php artisan config:publish edvinaskrucas/rbauth`Now you will be able to change default implementations i a file: `app/config/packages/edvinaskrucas/rbauth/`

Usage
-----

[](#usage)

### Basic examples

[](#basic-examples)

Sample RoleInterface and RoleProviderInterface implementations are included, but method `can($identifier)` must be implemented by user.

#### Logging in a user

[](#logging-in-a-user)

```
$input = Input::all();

try
{
    Auth::attempt(
        array(
            'email' => $input['email'],
            'password' => $input['password']
        ),
        isset($input['reminder'])
    );
    return Redirect::back(); // All is ok
}
catch(UserNotFoundException $e)
{
    // User not found
}
catch(UserPasswordIncorrectException $e)
{
    // Password incorrect
}
```

#### Determine if a logged in user is in a role

[](#determine-if-a-logged-in-user-is-in-a-role)

Returns boolean `true` (if has a role assigned) or `false` (if has not a role assigned)

```
Auth::is('admin');
```

#### Determine if a logged in user has permission to a resource

[](#determine-if-a-logged-in-user-has-permission-to-a-resource)

Returns boolean `true` (if can) or `false` (if can not)

```
Auth::can('view.profile');
```

### Extending Auth with your custom checks

[](#extending-auth-with-your-custom-checks)

Sometimes you need to check few rules on a certain object, so you can easily do that by adding your custom checks. This example shows how to check compound permissions. For example you have two permissions for editing a trip: `trips.edit.all` and `trips.edit.own`, you can use double check on a certain trip by using simple calls, or you just can use this example below.

```
Auth::rule('trips.edit', function($trip)
{
    if(Auth::can('trips.edit.all'))
    {
        return true;
    }
    elseif(Auth::can('trips.edit.own') && $trip->user_id == Auth::user()->id)
    {
        return true;
    }

    return false;
});
```

Now you can simply call method `can` with a new rule

```
if(Auth::can('trips.edit', $trip))
{
    echo 'ok';
}
```

### Route filters

[](#route-filters)

Package comes with couple route filters, one for simple check using `can` other for your custom checks `customCan:canEditTrip`

Simple example

```
Route::get('test', array('before' => 'can:test', function()
{
    echo 'I can test!';
}));
```

Now lets try using some our custom "can's"

First we need to bind some models to our routing

```
Route::bind('trip', function($value, $route)
{
    return Trip::find($value);
})
```

Now we can access our trip objects from a route.

```
Route::get('trips/edit/{trip}', array('before' => 'can:trips.edit,trip', function($trip)
{
    echo 'I can edit this trip!';
}));
```

So structure of custom route permission check is:

```
cam:trips.edit,trip

trips.edit - your rule name

trip - and other parameters are optional, this is usefull if you need to pass object to a custom check.
In this case (route filter) trip will be resolved from Route object, thats why we need to bind it.
When checking this in a controller or a view you can simply call it by "Auth::can('trips.edit', $trip)"
```

### Exceptions

[](#exceptions)

This auth extension throws two exceptions when you are trying to login:

`\Krucas\RBAuth\UserNotFoundException` - thrown when you are trying to login with non existing user. `\Krucas\RBAuth\PasswordIncorrectException` - thrown when password for user is incorrect.

### Default implementation features

[](#default-implementation-features)

- Users can be assigned to multiple roles
- Roles can have assigned accesses (permission with status enabled / disabled)
- Users can have assigned accesses (permission with status enabled / disabled)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0802c23b9fd902a5c8a571164693f46ae1c83e0b2c470941f3ca8d5f146c41d?d=identicon)[edvinaskrucas](/maintainers/edvinaskrucas)

---

Top Contributors

[![edvinaskrucas](https://avatars.githubusercontent.com/u/2177571?v=4)](https://github.com/edvinaskrucas "edvinaskrucas (79 commits)")

### Embed Badge

![Health badge](/badges/edvinaskrucas-rbauth/health.svg)

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

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.2M17](/packages/kartik-v-yii2-password)

PHPackages © 2026

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