Skip to content

obaaa8/laravel-admin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Admin Panel

An admin panel for managing users, roles, permissions & crud.

Requirements

Laravel >=5.1
PHP >= 5.5.9

Installation

  1. Run

    composer require appzcoder/laravel-admin:dev-master
    
  2. Add service provider to config/app.php file.

    'providers' => [
        ...
    
        Appzcoder\LaravelAdmin\LaravelAdminServiceProvider::class,
        // For crud generator & html
        Appzcoder\CrudGenerator\CrudGeneratorServiceProvider::class,
        Collective\Html\HtmlServiceProvider::class,
    ],
  3. Add Collective/Html aliases to config/app.php file.

    'aliases' => [
        ...
    
        'Form' => Collective\Html\FormFacade::class,
        'HTML' => Collective\Html\HtmlFacade::class,
    ],
  4. Run composer dump-autoload

  5. Publish the resource file.

    php artisan vendor:publish
    
  6. Make sure your user model's has a HasRoles trait app/User.php.

    class User extends Authenticatable
    {
        use Notifiable, HasRoles;
        
        ...
  7. Make sure your AuthServiceProvider app/Providers/AuthServiceProvider.php similiar this file.

  8. Run migrate command.

    php artisan migrate
    
  9. Put the routes definitions into Route file.

    Route::get('admin', 'Admin\\AdminController@index');
    Route::get('admin/give-role-permissions', 'Admin\\AdminController@getGiveRolePermissions');
    Route::post('admin/give-role-permissions', 'Admin\\AdminController@postGiveRolePermissions');
    Route::resource('admin/roles', 'Admin\\RolesController');
    Route::resource('admin/permissions', 'Admin\\PermissionsController');
    Route::resource('admin/users', 'Admin\\UsersController');
  10. If you don't have authentication resources then run below command.

    php artisan make:auth
    
  11. Overwrite default layout file with this file in order to use the package's layout file.

  12. You can generate CRUD easily through generator tool now.

Usage

  1. Create some roles.

  2. Create some permissions.

  3. Give permission(s) to a role.

  4. Create user(s) with role.

  5. For checking authenticated user's role see below:

    // Check role anywhere
    if(Auth::user()->hasRole('admin')) {
        // Do admin stuff here
    } else {
        // Do nothing
    }
    
    // Check role in route middleware
    Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'roles'], 'roles' => 'admin'], function () {
       Route::get('/', ['uses' => 'AdminController@index']);
    });
  6. For checking permissions see below:

    if($user->can('permission-name')) {
        // Do something
    }

Learn more about ACL from here

Screenshots

users

roles

new role

permissions

give permission to a role

generator

##Author

Sohel Amin

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%