Thursday, March 2, 2017

Roles and Permissions Laravel

I am a little bit confused with how to grant permissions depending on the user that it's logged in. On my Users table I have a field called "position", which they will be able to choose when they are registering This roles are saved as well in the db. Now I want that depending on their role, I get different layouts and different contents, for example, in my case I don't want the secretary to be able to see the expenses table and information. So in reality, I will have only the administrator and the secretary as roles, I tried to just check for the role but it's not working.

@if(Auth::user->role() == 'admin')
@extends('layouts.expenses')
@endif

I have seen several examples where there is need to install new dependencies to laravel like the "Entrust" one, but I don't know if there is something easier since my project it's already done, I am just missing this. I would gladly appreciate any advice or help that you can gave me. Thank you




via Lety Nava

Advertisement