I usually make my own back-end, with packages like entrust and a random bootstrap template that suits my needs.
Then I just put my views in views / admin and my controllers in Controller / admin and put all the admin routes in a group with middleware attached to it
Route::group(['namespace'=>'Admin','prefix'=>'admin','middleware'=>'role','role'=>'admin'],function(){ Route::get('/','HomeController@index'); }
and then in middleware (this is used by entrust ).
public function handle($request, Closure $next) { $user = $this->auth->user(); $route = $request->route(); if($user && $route) { $actions = $route->getAction(); if(array_key_exists('role',$actions)) { $role=$actions['role']; if(!$user->hasRole($role)) { Flash::error('Unauthorized Access'); abort(401); } } else { Flash::error('Unauthorized Access'); abort(401); } } else { Flash::error('Unauthorized Access'); abort(401); } return $next($request); }
Remember to register the middleware in the kernel.php file next to the routes file.
The middleware might look complicated, but itβs just checked if you put the role in your en group, and then if the current registered user belongs to this group.
Also remember that when routing using action() you need to place the admin namespace before the controller name, for example action('Admin\HomeController@index')
aranna
source share