acmepackage/laravel-admin

Laravel Admin Panel

v1.1.2 2022-10-30 15:51 UTC

This package is not auto-updated.

Last update: 2024-11-11 17:57:25 UTC


README

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

Requirements

Laravel >=9
PHP >= 8.0
composer `2.4.2`
node `16.17.1`
npm `8.15.0`
WebPack and laravel mix
Now we Support Laravel 9

templates version

Bootstrap v4

AdminLTE 3.1

Features

  • User, Role & Permission Manager
  • CRUD Generator
  • Activity Log
  • Page CRUD
  • Settings

Installation

  1. Run
     composer require acmepackage/laravel-admin
    
  2. Make sure your user model's has a `HasRoles` trait app/Models/User.php.

     class User extends Authenticatable
     {
         use Notifiable, HasRoles;
    
         ...
    
  3. Create auth assets
      php artisan ui bootstrap --auth  
    

    and don't replace auth views

  4. Add the following line to the "web.php" file located in routes folder

     require('admin.php');
    
  5. Register localization middleware in app/Http/Kernel.php

protected $middlewareGroups = [
'web' => [

            \App\Http\Middleware\Localization::class,

        ],

    ];
  1. Run the following command
    php artisan vendor:publish --all
    
  2. Remove your package.json located in the project root dir and rename package.json.example in the same dir to package.json then rename webpack.mix.js.example to webpack.mix.js

  3. Run the following commands to install node and build the node packages

     npm install
    
     npm install --save-dev webpack
    
      npm run dev
    
  4. To create seeder for roles and language, add the following lines to DatabaseSeeder.php in the "run" function

      $this->call([
              RoleTableSeeder::class,
             LanguageTableSeeder::class,
         ]);
    
  5. Finally run

      php artisan migrate --seed
    
  6. Open the following url after running "php artisan serve" your_url/admin

Note: we use webpack only not vite

Note: If you are using Laravel 7+ then scaffold the authentication with bootstrap for a better experience. . You can generate CRUD easily through generator tool now.

Usage

  1. Create some permissions.

  2. Create some roles.

  3. Assign permission(s) to role.

  4. Create user(s) with role.

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

     // Add role middleware in app/Http/Kernel.php
     protected $routeMiddleware = [
         ...
         'role' => \App\Http\Middleware\CheckRole::class,
     ];
    
     // Check role anywhere
     if (Auth::check() && Auth::user()->hasRole('admin')) {
         // Do admin stuff here
     } else {
         // Do nothing
     }
    
     // Check role in route middleware
     Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth', 'role:admin']], function () {
        Route::get('/', ['uses' => 'AdminController@index']);
     });
    
     // Check permission in route middleware
     Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth', 'can:write_user']], 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

For activity log please read spatie/laravel-activitylog docs

Screenshots

users

activity log

generator

settings

Author

[Mohamed Hassan] :email: Email Me

reference

Sohel Amin :email: Email Me

License

This project is licensed under the MIT License - see the License File for details