0

I have to create an application with 5 types of roles.

So I started nesting my controllers

Controllers administrator/establishments.php supervisor/establishments.php

Views

administrator/establishments/index.php supervisors/establishments/index.php

But I noticed that they have almost THE SAME CODE and the count of files will be huge!


I have been thinking in some ways to solve this

Controllers

establishments.php

and then ask:

if (Request::is('admin/*'))
{
    Establishments::paginate(20);
}

if (Request::is('supervisor/*'))
{
    Establishments::where_country(1)->paginate(20);
}

same for views.


Save role on session info, and create a menu to switch the var from one user to another

$role = Session::get('role');

if ($role == 'admin'))
{
    Establishments::paginate(20);
}

if ($role == 'supervisor'))
{
    Establishments::where_country(1)->paginate(20);
}

Any other ideas or suggestions?

JCielo
  • 15
  • 1
  • 5

1 Answers1

0

What you could do is build a 'BaseCOntroller' wich has all the required logic in it. On top of that you create the 5 other controllers - extend them on the BaseController. Via the __construct() method you will pass the type so the BaseController knows what it has to do.

Rob Gordijn
  • 6,381
  • 1
  • 22
  • 29