A
A
Alexander2016-11-01 15:29:28
Laravel
Alexander, 2016-11-01 15:29:28

What RBAC are you using for laravel 5.3?

Are there working Open source RBAC projects for Laravel 5.3? stumbled upon two repos 1: https://github.com/klaravel/ntrust , 2 https://github.com/DynamicCodeNinja/RBAC
But both have installation errors.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Mikhail Osher, 2016-11-01
@kentuck1213

Out of the box , everything is very flexible.
I refused only the Policy generator, and all validations through the Gate contract in the FormRequest in the authorize method.
Somehow it all works out.
// form request

<?php

namespace App\Http\Requests\User;

use App\Models\User;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Foundation\Http\FormRequest;

class DestroyRequest extends FormRequest
{
    public function authorize(Gate $gate)
    {
        $id = $this->route()->getParameter('user');

        return $gate->authorize('destroy', User::query()->findOrFail($id));
    }

    public function rules()
    {
        return [

        ];
    }
}

// controller
<?php

namespace App\Http\Controllers\Api;

use App\Contracts\IUsersService;
use App\Http\Controllers\Controller;
use App\Http\Requests\User\DestroyRequest;
use App\Http\Requests\User\IndexRequest;

class UsersController extends Controller
{
    public function destroy(DestroyRequest $request, $id)
    {
        // do stuff
    }
}

// policy
<?php

namespace App\Policies;

use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class UserPolicy
{
    use HandlesAuthorization;

    public function index()
    {
        return true;
    }

    /**
     * rbac:user.destroy
     */
    public function destroy(User $user, User $entity)
    {
        if ($entity->hasRole(User::ROLE_ROOT)) {
            return false;
        }

        return $user->isEditor();
    }
}

S
Stanislav Pochepko, 2016-11-01
@DJZT

https://cartalyst.com/manual/sentinel/2.0

A
Andrzej Wielski, 2016-11-01
@wielski

Use https://github.com/Zizaco/entrust
On the latest versions of Laravel, there may be an error, you need to manually register the user table in the migration.

G
grigoralex, 2018-08-19
@grigoralex

You can try this option https://github.com/itstructure/laravel-rbac

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question