Guest, admin and Owner roles in PHP (Laravel) project

855 Views Asked by At

I'm building a Laravel application. I need to discriminate between a guest, an admin and an owner. I plan on using Confide and Entrust. Let me give the example with a todo-application:

First part of the question: The guest can only access the frontend, the admin can access the backend to add/edit his 'own' projects and to do items. The owner can get a view on all projects of all registered users, can also see stats on how many projects and tasks, how many users are using the app, reset passwords for a given users, ticketing system etc....

I would create three roles: guest, admin and owner (using Entrust). Then I would (in the router file) say that all routes starting with admin would need to be authenticated. But how to solve this for the 'owner'. So I have the following situation:

1) Routes for guest: Route::group(array('before' => 'guest'), function(){....} 2) Routes for admin: Route::group(array('prefix' => 'admin', 'before' => 'auth'), function() { ...} 3) Routes for owner: ??

How to fix the owner routes: Is it as easy as doing: Route::group(array('prefix' => 'owner', 'before' => 'auth'), function() { } or should I take the owner as part of the 'admin' section and do the discrimination in the controllers?

Second part of the question: how can I ensure that a user that subscribes to the app is automatically assigned the admin role.

Third part of the question: how can I ensure that only 1 owner can access the application with full rights?

1

There are 1 best solutions below

0
On

You need to use acl here:

https://github.com/intrip/laravel-authentication-acl

read more about acl (if youve never used it before) here: http://en.wikipedia.org/wiki/Access_control_list

I come from cakephp where usually /admin/* is authed content, within the app you can detect which user you are serving content to, so then you can send them to one content or another.

Upon signing up, set the group to admin (easy)

Third part of the question you will have to clear out. I dont know if you need one admin, or first admin, etc.