I am building an app using Laravel 4.1. My app needs to have two types of different users, admin and clients. To achieve this I have added a type column to the user table and created customs filters in /app/filters.php.
Route::filter('admin', function()
{
if (Auth::guest() || Auth::user()->type !== 1) return Redirect::to('/');
});
Route::filter('client', function()
{
if (Auth::guest() || Auth::user()->type != 2) return Redirect::to('/');
});
Then I have created Route::group in /app/routes.php
/* Admin */
Route::group(array('before' => 'admin'), function()
{
Route::get('admin', function(){ return "admin index"; });
Route::get('ejemplo', function(){ return "admin ejmplo"; });
});
/* Client */
Route::group(array('before' => 'client'), function()
{
Route::get('client', function(){ return "client index"; });
Route::get('ejemplo', function(){ return "client ejmplo"; });
});
The problem that I am facing is that I cant access Route::get('ejemplo'), I thought about a solution for this:
- Adding if statements within the Route Group, so only Auth::user()->type( [x] ) could access certain routes.
But since I am quite new to laravel I wouldnt like to mess up my code making it unscalable or unmaintainable.
I am open to any other solution or structure design,
Thank you very much in advance. Cheers
type
really an int1
, for example?) – Damien Pirsyejemplo
as aclient
? – Marwelln