openstrongtw / laravel-strongadmin
在1分鐘內構建一個功能齊全的管理後臺。基於 layui 前端框架開發的 Laravel 後臺管理框架。功能有 許可權管理、菜單管理、角色管理、日誌記錄等。
Installs: 24
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:laravel-extension
Requires
- php: >=7.0
- laravel/framework: >=5.5
- mews/captcha: ^3.2
- openstrongtw/laravel-strongstub: >=1.0
Replaces
This package is not auto-updated.
Last update: 2025-03-02 01:22:14 UTC
README
在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
瀏覽
更新 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
- 執行
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.
- 新增路由: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');
});
- 把路由新增到 許可權菜單=》菜單管理
開發
新增控制器
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
重構
這裡以重構登錄為例
-
重構控制器 新建 app/Http/Controllers/Strongadmin/AdminAuthController
class AdminAuthController extends \OpenStrong\StrongAdmin\Http\Controllers\AdminAuthController { public function login(Request $request) { } }
-
重構路由
Route::middleware(['strongadmin'])->group(function() { Route::any('strongadmin/login', 'Strongadmin\AdminAuthController@login'); });
使用此擴充套件包的開源專案
StrongShop 開源跨境商城 https://gitee.com/openstrong/strongshop
QQ群:557655631