PHPackages                             wdevkit/laravel-admin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. wdevkit/laravel-admin

ActiveLibrary[Admin Panels](/categories/admin)

wdevkit/laravel-admin
=====================

Admin scaffolding for Laravel

0252[1 issues](https://github.com/wdevkit/laravel-admin/issues)PHP

Since Sep 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/wdevkit/laravel-admin)[ Packagist](https://packagist.org/packages/wdevkit/laravel-admin)[ RSS](/packages/wdevkit-laravel-admin/feed)WikiDiscussions develop Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Admin scaffolding for Laravel
=============================

[](#admin-scaffolding-for-laravel)

This package allows you to scafold a simple *admin* structure to your application. It's Laravel 8 compatible!

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require wdevkit/laravel-admin
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Wdevkit\Admin\AdminServiceProvider" --tag="migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Wdevkit\Admin\AdminServiceProvider" --tag="config"
```

You can publish the routes file with:

```
php artisan vendor:publish --provider="Wdevkit\Admin\AdminServiceProvider" --tag="routes"
```

You can publish the views files with:

```
php artisan vendor:publish --provider="Wdevkit\Admin\AdminServiceProvider" --tag="views"
```

This is the contents of the published config file:

```
return [
];
```

Usage
-----

[](#usage)

### Create Admin

[](#create-admin)

To create a admin user, you can use the `admin:create` command.

```
php artisan admin:create
```

You will be asked to input a admin name, email, password and password confirmation. Alternatively, you can use the one line command to input all the required arguments:

```
php artisan admin:create "John Doe" johndoe@email.test 1234 1234
```

### Guard &amp; User provider Structure

[](#guard--user-provider-structure)

After publishing the migrations, the model `Wdevkit\Admin\Models\Admin::class` will be available. You can use this model to define a new user provider in the `config/auth.php` file:

```
return [

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        // new user provider
        'admins' => [
            'driver' => 'eloquent',
            'model' => Webdk\Admin\Models\Admin::class,
        ],
    ],
];
```

By creating the `admins` user provider, you can use it in your *guards* (web, api) or you can create a new *guard* which uses the *admins* user provider in the `config/auth.php` file:

```
return [

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'admins', // you can update the `web` guard to use the `admins` user provider
        ],

        // or you can create your own `guard` with the `admins` user provider.
        'web_admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ]
    ],
];
```

When using the auth structure with the `web_admin` guard, you should also update the `app/Http/Middleware/Authenticate.php` middleware to correctly redirect the request to the admin login route, by updating the `redirectTo` method:

```
protected function redirectTo($request)
{
    if (! $request->expectsJson()) {

        // ensure it will redirect to correct login route.
        if ($request->is('admin/*')) {
            return route('wdevkit_admin.login');
        }

        return route('login');
    }
}
```

And also update the method `handle` on the `app/Http/Middleware/RedirectIfAuthenticated.php` middleware to correctly redirect to the admin home page when already authenticated:

```
public function handle($request, Closure $next, ...$guards)
{
    $guards = empty($guards) ? [null] : $guards;

    foreach ($guards as $guard) {
        if (Auth::guard($guard)->check()) {

            // redirect to /admin/home when guard is web_admin
            if ($guard == 'web_admin') {
                return redirect('/admin/home');
            }

            return redirect(RouteServiceProvider::HOME);
        }
    }

    return $next($request);
}
```

### Routing

[](#routing)

The `routes` publishing will create a `routes/admin.php` routes file in your application. You can use this admin routes file to tweak the package routes accordingly to your needs. In this routes file, you can override the packages controllers as you wish. If the admin routes is not published, the default admin routes file from the package will be used.

```
