Best practice for creating admin interface in Laravel 5

I recently started to learn Laravel 5 and I need to create a separate admin area on the site.

I tried a lot to get the file directory structure, but most of them I got for Laravel 4, not for Laravel 5.

Since Laravel 5 is different in structure from Laravel 4.

Can someone help me set up the directory structure for the admin area and routes.

Thanks in advance.

+8
php admin laravel-5
source share
2 answers

I recently created a project in Laravel 5 with an admin area. I used the advanced ACL (access control level) to grant privileges to administrators of the rights to the role. For this I used Entrust Package . Then I used the base auth Laravel 5 and implemented Entrust.

I easily created an administration area with all permissions. I also tried setting automatic permissions in the Authenticate.php middleware

You can refer to this question Entrust Automate , I asked. But later I found a solution. I would suggest you follow the URL-based architecture, and then the old folder structure method for admin management. Laravel 5 is best suited for URLs, which will also help you create any API if you need future mobile apps.

Hope this helps you.

+2
source share

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')

+2
source share

All Articles