thalles/baseadmin

一个使用adminlte搭建具有认证和用户CRUD功能的后台管理工具!

v1.0.0 2020-03-24 23:24 UTC

This package is auto-updated.

Last update: 2024-09-25 13:50:32 UTC


README

Latest Version on Packagist Total Downloads

一个使用adminlte搭建具有认证和用户CRUD功能的后台管理工具!

需求

  • PHP >= 7.2.5
  • laravel/framework ^7.0

1. 安装

  1. 使用composer安装包
composer require thalles/baseadmin
  1. (Laravel 7+仅限) 使用composer安装laravel/ui包
composer require laravel/ui

2. 配置

  1. 发布自定义adminlte配置文件
php artisan vendor:publish --tag=config
  1. 使用命令安装adminlte包(适用于新Laravel安装)
php artisan adminlte:install
  • 如果出现问题,您需要清除配置缓存
php artisan config:clear

有关Laravel-AdminLTE的更多信息,请参阅文档

  1. 配置用户角色枚举

    • 创建枚举
    php artisan make:enum UserRole
    
    • 现在,您只需将枚举可能具有的值作为常量添加进去。
    <?php
    
        namespace App\Enums;
    
        use BenSampo\Enum\Enum;
    
        /**
        * @method static static OptionOne()
        * @method static static OptionTwo()
        * @method static static OptionThree()
        */
        final class UserRole extends Enum
        {
            const Administrator = 1;
    
            /**
            * Return the translated key name
            *
            * @param integer $value
            * @return string
            */
            public static function getTranslatedKey($value)
            {
                switch ($value) {
                    case self::Administrator:
                        $keyName = 'Administrador';
                        break;
                    default:
                        $keyName = 'Outro';
                        break;
                }
    
                return $keyName;
            }
        }
    

    有关枚举的更多信息,请参阅文档

  2. 将中间件认证路由更改为"admin.login"

<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('admin.login');
        }
    }
}
  1. 运行迁移和种子。

  2. 发布路由和视图

    • 视图
    php artisan vendor:publish --tag=views
    
    • 路由
    php artisan vendor:publish --tag=routes
    

3. 使用方法

要使用admin路由文件,您需要注册它们。为此,在RouteServiceProvider.php文件中插入以下方法

/**
* Define the "admin" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapAdminRoutes()
{
    Route::middleware('web')
            ->group(base_path('routes/admin.php'));
}

在此之前,映射此方法

/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
    ...

    $this->mapAdminRoutes();
}