4 Star 9 Fork 4

OpenStrong / laravel-strongadmin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Larevel-StrongAdmin

在1分钟内构建一个功能齐全的管理后台。

基于 layui 前端框架开发的 Laravel 后台管理框架。同时拥有 api 接口,配合前端 VUE 开发。功能如下:

  • 权限管理
  • 菜单管理
  • 角色管理
  • 日志记录
  • 管理员账号

演示站点

http://demo.strongadmin.strongshop.cn/strongadmin

演示账号:admin
演示密码:123456

查看接口文档

点击查看

安装

你可以使用 Composer 在 Laravel 5|6|7|8 项目中安装 laravel-strongadmin 扩展:

composer require openstrong/laravel-strongadmin

安装 laravel-strongadmin 后,可以在 Artisan 使用 strongadmin:install 命令来配置扩展实例。安装 laravel-strongadmin 后,还应运行 migrate 命令:

php artisan strongadmin:install

php artisan migrate

浏览

http://你的域名/strongadmin

更新 laravel-strongadmin

更新 laravel-strongadmin 时,您应该重新配置加载 laravel-strongadmin 实例:

php artisan strongadmin:publish

配置

使用 laravel-strongadmin,其主要配置文件将位于 config/strongadmin.php。每个配置选项都包含其用途说明,因此请务必彻底浏览此文件。

/*
  |--------------------------------------------------------------------------
  | 启用 StrongAdmin
  |--------------------------------------------------------------------------
 */
'enabled' => env('STRONGADMIN_ENABLED', true),

/*
  |--------------------------------------------------------------------------
  | StrongAdmin 子域名
  |--------------------------------------------------------------------------
  |
  | 设置后即可支持域名访问
  |
 */
'domain' => env('STRONGADMIN_DOMAIN', null),

/*
  |--------------------------------------------------------------------------
  | StrongAdmin Path
  |--------------------------------------------------------------------------
  |
  | StrongAdmin 访问路径(也是路由前缀),如果修改此项,请记得修改以下配置 `ignore_auth_check_url`、`ignore_permission_check_url`
  |
 */
'path' => env('STRONGADMIN_PATH', 'strongadmin'),

/*
  |--------------------------------------------------------------------------
  | StrongAdmin 数据配置
  |--------------------------------------------------------------------------
  |
  | 1.在这可以自定义 StrongAdmin 数据库连接的数据库
  | 2.修改默认 后台超级管理员 账号信息(仅安装初始化有效)
  | 3.修改图片验证码配置
  |
 */
'storage' => [
    //数据库
    'database' => [
        'connection' => env('DB_CONNECTION', 'mysql'), //数据库连接
    ],
    //后台超级管理员(仅安装初始化有效)
    'super_admin' => [
        'user_name' => 'admin', //账号名称
        'password' => '123456', //账号密码
    ],
    //登录限制
    'throttles_logins' => [
        'maxAttempts' => 5, //允许尝试登录最大次数
        'decayMinutes' => 10, //登录错误超过 maxAttempts 次, 禁止登录 decayMinutes 分钟
    ],
    //图片验证码
    'captcha'=>[
        'length' => 4, //字符长度
        'width' => 120, //宽
        'height' => 44, //高
        'expire' => 60, //有效期 秒
    ],
],

/*
  |--------------------------------------------------------------------------
  | StrongAdmin 中间件
  |--------------------------------------------------------------------------
  |
 */
'middleware' => [
    'web',
    OpenStrong\StrongAdmin\Http\Middleware\Auth::class, //登录认证检测
    OpenStrong\StrongAdmin\Http\Middleware\CheckPermission::class, //权限检测
    OpenStrong\StrongAdmin\Http\Middleware\Log::class, //日志记录
],

/*
  |--------------------------------------------------------------------------
  | StrongAdmin Auth Guard 登录认证看守器名称。不建议修改此项,如果修改此项则必须修改相对应的 `config/auth.php` 里的 `guards` 配置项
  |--------------------------------------------------------------------------
  | auth('strongadmin')->user() --- 获取登录用户信息
  | auth('strongadmin')->id()   --- 获取登录用户id
 */
'guard' => 'strongadmin',

/*
  |--------------------------------------------------------------------------
  | 忽略登录检测的路由
  |--------------------------------------------------------------------------
 */
'ignore_auth_check_url' => ['strongadmin/login', 'strongadmin/logout', 'strongadmin/captcha'],

/*
  |--------------------------------------------------------------------------
  | 忽略权限检测的路由
  |--------------------------------------------------------------------------
 */
'ignore_permission_check_url' => ['strongadmin'],

快速构建

使用 artisan 命令快速生成 CURD 增删改查的控制器和视图

此命令使用扩展包 laravel-strongstub,详细文档:https://gitee.com/openstrong/laravel-strongstub

  1. 执行strongstub:curd命令:
    php artisan strongstub:curd Strongadmin/TesetAdminUserController -m App\\Models\\StrongadminUser --view
    结果:
     A App\Models\StrongadminUser model does not exist. Do you want to generate it? (yes/no) [yes]:
     >
    
    Model created successfully.
    Controller created successfully.
    
    Route::any('strongadmin/tesetAdminUser/index', 'Strongadmin\TesetAdminUserController@index');
    Route::any('strongadmin/tesetAdminUser/show', 'Strongadmin\TesetAdminUserController@show');
    Route::any('strongadmin/tesetAdminUser/create', 'Strongadmin\TesetAdminUserController@create');
    Route::any('strongadmin/tesetAdminUser/update', 'Strongadmin\TesetAdminUserController@update');
    Route::any('strongadmin/tesetAdminUser/destroy', 'Strongadmin\TesetAdminUserController@destroy');
    
    id:
    user_name:
    password:
    remember_token:
    name:
    email:
    phone:
    avatar:
    introduction:
    status:
    last_ip:
    last_at:
    created_at:
    updated_at:
    
    {"id":"","user_name":"","password":"","remember_token":"","name":"","email":"","phone":"","avatar":"","introduction":"","status":"","last_ip":"","last_at
    ":"","created_at":"","updated_at":""}
    
    Blade View`F:\phpstudy_pro\WWW_openstrong\strongadmin\resources\views/strongadmin/tesetAdminUser/form.blade.php` created successfully.
    Blade View`F:\phpstudy_pro\WWW_openstrong\strongadmin\resources\views/strongadmin/tesetAdminUser/index.blade.php` created successfully.
    Blade View`F:\phpstudy_pro\WWW_openstrong\strongadmin\resources\views/strongadmin/tesetAdminUser/show.blade.php` created successfully.
  2. 添加路由:app/routes/web.php
Route::middleware(['strongadmin'])->group(function () {
    Route::any('strongadmin/tesetAdminUser/index', 'Strongadmin\TesetAdminUserController@index');
    Route::any('strongadmin/tesetAdminUser/show', 'Strongadmin\TesetAdminUserController@show');
    Route::any('strongadmin/tesetAdminUser/create', 'Strongadmin\TesetAdminUserController@create');
    Route::any('strongadmin/tesetAdminUser/update', 'Strongadmin\TesetAdminUserController@update');
    Route::any('strongadmin/tesetAdminUser/destroy', 'Strongadmin\TesetAdminUserController@destroy');
});
  1. 把路由添加到 权限菜单=》菜单管理

开发

新增控制器

app/Http/Controllers/Strongadmin/AdminUserController

这里一定要继承控制器 '\OpenStrong\StrongAdmin\Http\Controllers\BaseController'

use \OpenStrong\StrongAdmin\Models\StrongadminUser;
class AdminUserController extends \OpenStrong\StrongAdmin\Http\Controllers\BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        if (!$request->expectsJson())
        {
            return $this->view('adminUser.index');
        }
        $model = StrongadminUser::query();
        $rows = $model->paginate();
        return ['code' => 200, 'message' => __('admin.Success'), 'data' => $rows];
    }
}

新增路由

Route::middleware(['strongadmin'])->group(function() {
    Route::any('strongadmin/product/index', 'Strongadmin\AdminUserController@index');
});

新增视图

resources/views/strongadmin/adminUser/index.blade.php

这里一定要继承视图模板 strongadmin::layouts.app

@extends('strongadmin::layouts.app')

@push('styles')
    <style></style>
@endpush

@push('scripts')
    <script>
    //......
    </script>
@endpush

@section('content')
    <div class="st-h15"></div>
    <form class="layui-form st-form-search" lay-filter="ST-FORM-SEARCH">
        ...
    </form>
@endsection

@push('scripts_bottom')        
    <script>
    !function () {
        //...
    }();
    </script>
@endpush

重构

这里以重构登录为例

  1. 重构控制器 新建 app/Http/Controllers/Strongadmin/AdminAuthController

    class AdminAuthController extends \OpenStrong\StrongAdmin\Http\Controllers\AdminAuthController
    {
        public function login(Request $request)
        {
    
        }
    }
  2. 重构路由

    Route::middleware(['strongadmin'])->group(function() {
        Route::any('strongadmin/login', 'Strongadmin\AdminAuthController@login');
    });

使用此扩展包的开源项目

StrongShop 开源跨境商城 https://gitee.com/openstrong/strongshop

QQ群:557655631

MIT License Copyright (c) 2021 openstrong Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

在1分钟内构建一个功能齐全的管理后台。基于 layui 前端框架开发的 Laravel 后台管理框架。功能如下:权限管理、菜单管理、角色管理、日志记录、管理员账号 展开 收起
PHP 等 4 种语言
MIT
取消

发行版 (10)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/openstrong/laravel-strongadmin.git
git@gitee.com:openstrong/laravel-strongadmin.git
openstrong
laravel-strongadmin
laravel-strongadmin
master

搜索帮助