PHP code example of mohamadtsn / laravel-supernova

1. Go to this page and download the library: Download mohamadtsn/laravel-supernova library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mohamadtsn / laravel-supernova example snippets


'locale' => 'fa',

use Mohamadtsn\Supernova\Models\User as SupernovaUser; // use supernova User Model
use Mohamadtsn\Supernova\Classes\Traits\PermissionWrapper;
class User extends SupernovaUser
{
    use HasApiTokens, HasFactory, Notifiable, PermissionWrapper;
    // other class methods
}

protected $fillable = [
    'level',
];

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

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

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
    ];
}

protected function redirectTo($request)
{
        if ($request->expectsJson()) {
            return response()->json([
                'title' => 'access denied',
                'text' => 'unauthorized ...!',
                'type' => 'error'
            ], Response::HTTP_FORBIDDEN);
        }
        return route('panel.login');
}

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
    });
}

public function boot()
{
    $this->routes(function () {
        // other routes file
        Route::middleware('web')
                ->namespace($this->namespace)
                ->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
    });
}

  return [
      // other configs
      'management_url' => env('APP_MANAGEMENT_URL', 'http://management.example.test'),
  ]
  
bash
php artisan supernova:publish [tags] --force
bash
php artisan supernova:publish [tags] --force
bash
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
bash
 composer dump-autoload
bash
  php artisan supernova:publish supernova-basic-routes --force
  
bash
php artisan serve