mohamadtsn/laravel-supernova

it's a basic Management panel for laravel application

2.1.10 2022-07-05 07:51 UTC

This package is auto-updated.

Last update: 2022-08-05 07:57:37 UTC


README

Supernova image

Give a professional and powerful management panel as your Laravel App gift. 🎁

Installation: ⬇️

composer require mohamadtsn/laravel-supernova

configuration: ⚙️

Publish config file

php artisan vendor:publish --tag=supernova-config --force

Change locale to fa in config/app.php

'locale' => 'fa',

🔌 (For Laravel <=5.4) Next, you must add the service provider to config/app.php 🔌

'providers' => [
    // for laravel 5.4 and below
    App\Providers\MetronicServiceProvider::class,
];

Add this to your Aliases in config/app.php

'aliases' => [
    // other aliases
    'Supernova' => App\Classes\Theme\Supernova::class,
    'Menu' => App\Classes\Theme\Menu::class,
],

Do in Laravel 8:

Put this in App\Models\User.php

use Spatie\Permission\Traits\HasRoles; // use permission trait

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasRoles // use trait in User class;
    // other class methods
}

Add level to fillable fields in App\Models\User.php.

protected $fillable = [
    'level',
];

Change composer.json autoload section and add helpers.php to files section like below:

{
  "autoload": {
    "psr-4": {
      "...": "PSR-4 values"
    },
    "files": [
      "app/Tools/helpers.php"
    ]
  }
}

Add these seeders call in Database\Seeders\DatabaseSeeder.php in run() method:

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        // Other seeders call
        // You add seeders
        $this->call(UserSeeder::class); // #1
        $this->call(PermissionSeeder::class); // #2
    }
}

Add these into guards section in config/auth.php:

'guards' => [
    // other guard
    'admin' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
],

Put these in app/Http/Kernel.php like below:

use App\Http\Middleware\Panel\CheckPermission; // use Middleware class CheckPermission

class Kernel extends HttpKernel
{
    protected $routeMiddleware = [
        // other routeMiddleware
        'permission' => CheckPermission::class, // add CheckPermission::class on this section
    ];
}

Change these in App/Http/Middleware/Authenticate.php in redirectTo method like below:

protected function redirectTo($request)
{
    if (! $request->expectsJson()) {
        return route('panel.login'); // change this section to `return route('panel.login')`
    }
}

add admin panel routes file routes/admin.php to App/Providers/RouteServiceProvider.php in boot() method

IMPORTANT!! Be sure to add before `web.php`.

Look carefully:
public function boot()
{
    $this->routes(function () {
        // other routes file
        Route::middleware('web')
                ->namespace($this->namespace)
                ->domain(config('supernova.management_url'))
                ->group(base_path('routes/admin.php')); // #1 add admin panel routes (admin.php)
        
        Route::middleware('web')
                ->namespace($this->namespace)
                ->domain(config('app.url'))
                ->group(base_path('routes/web.php')); // #2 web.php routes
    });
}

Setup Schema:

  1. Set database config connection in .env file
  2. Migrate and seeding using the following commands:
php artisan migrate:fresh --seed        // "Associated with" Drop All Tables & Migrate and seeding
"Or"
php artisan migrate --seed              // "Without" Drop All Tables & Migrate and seeding

re-generate composer autoload:

 composer dump-autoload

Usage

Method #1 ====> Setup with virtual host

  • Build a virtual subdomain with name Management

    • Example:
      • origin domain => example.test // Main URL
      • subdomain domain => management.example.test // Admin Panel URL
  • add param Admin Panel URL to env file with name APP_MANAGEMENT_URL like below:

    APP_URL= http://shop.test
    APP_MANAGEMENT_URL= http://management.shop.test
  • add config Admin Panel URL to config/supernova.php file with name management_url like below:

    return [
        // other configs
        'management_url' => env('APP_MANAGEMENT_URL', 'http://management.example.test'),
    ]
  • Login to Panel management.example.test/login

  • Dashboard Panel management.example.test/

Method #2 ====> Setup without virtual host

  1. publish basic routes:
php artisan vendor:publish --tag=basic-routes --force
  1. serve app with command:
php artisan serve
  1. Tip: You have access to Supernova Panel Routes only with Prefix panel
  2. Go to 127.0.0.1:8000/panel/login

Login to Panel

  • Email: admin@gmail.com
  • Password: supernova@123

Enjoy it 👋