Support the ongoing development of Laravel.io →
Authentication Views Architecture
Last updated 4 months ago.
0

If you are using the entrust library you can set the role specific things with an $user->hasRole('role') control structure.

Last updated 4 months ago.
0

thanks

how would you go about designing the directory structure?

A view directory per each user role with it's partials ?

Views/Admin/layouts Views/Member/layouts etc?

Last updated 4 months ago.
0

I attach "is" and "can" methods to my User object. So I can do things like:

Auth::user()->is('admin');
Auth::user()->can('manage users');

I also use a permissions filter:

Route::filter('permission', function ($route, $request, $permission) {
        if (!Auth::user()->can($permission)) {
            return Redirect::route('dashboard')
                ->with('flash_error', 'You do not have permission to view this page.');
        }
    }
);

You can use that filter in any routes or even do it in a resource controller as follows:

public function __construct()
{
    parent::__construct();
    $this->beforeFilter('permission:manage users');
}

In your views you can do something like this (for small projects):

@if(Auth::user()->can('manage users'))
    {{-- Show menu item here --}}
@endif
Last updated 4 months ago.
0

thanks @orecrush, very useful

Last updated 4 months ago.
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

dflow dflow Joined 16 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.