PHPackages                             jjg/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. jjg/admin

ActiveLibrary[Admin Panels](/categories/admin)

jjg/admin
=========

A package for laravel backend dev start

v0.1.17(7y ago)03521MITHTML

Since Jan 4Pushed 6y agoCompare

[ Source](https://github.com/mljjg/mladmin)[ Packagist](https://packagist.org/packages/jjg/admin)[ RSS](/packages/jjg-admin/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (6)Versions (19)Used By (0)

Laravel 后台开发扩展包
---------------

[](#laravel-后台开发扩展包)

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

[](#installation)

> This package requires PHP 7+ and Laravel 5.5

First, install laravel 5.5, and make sure that the database connection settings are correct.

```
composer require jjg/admin

```

Then run these commands to publish assets and config：

```
php artisan vendor:publish --provider="Ml\Providers\MlServiceProvider"

```

After run command you can find config file in `config/admin.php`, in this file you can change the install directory,db connection or table names.

At last run following command to finish install.

```
php artisan mlAdmin:install

```

##### 修改 auth 的 users model

[](#修改-auth-的-users-model)

config/auth.php

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

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

```

重写异常类的 unauthenticated 方法：app/Exceptions/Handler.php （mladmin:install 若未选择替换，则需要手动配置）

```
use Illuminate\Auth\AuthenticationException;

/**
     * Render an exception into an HTTP response.
     * @param \Illuminate\Http\Request $request
     * @param Exception $exception
     * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function render($request, Exception $exception)
    {
        if ($exception instanceof AuthorizationException) {
            return redirect()->guest(route('admin.permission-denied'));
        }

        return parent::render($request, $exception);
    }

 /**
     * Convert an authentication exception into a response.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Illuminate\Auth\AuthenticationException $exception
     * @return \Illuminate\Http\Response
     */
    protected function unauthenticated($request, AuthenticationException $exception)
    {
        // 自定义登录跳转-通过路由前缀判断
        $action = $request->route()->getAction();

        $redirectUrl = (isset($action['prefix']) && (config('admin.route.prefix') == $action['prefix'] || '/' . config('admin.route.prefix') == $action['prefix'])) ?
            route('admin.login') : route('login');

        return $request->expectsJson()
            ? response()->json(['message' => $exception->getMessage()], 401)
            : redirect()->guest($redirectUrl);

//        return $request->expectsJson()
//            ? response()->json(['message' => $exception->getMessage()], 401)
//            : redirect()->guest(route('login'));
    }
```

#### 策略类注册（需要手动添加）

[](#策略类注册需要手动添加)

```
