PHP >=7.0.0
Laravel >= 5.5.0
安裝最新版的 laravel 5.7
$ composer create-project --prefer-dist laravel/laravel blog
安裝laravel-admin
$ composer require encore/laravel-admin
列出你裝了哪些packages
$ composer show -i
發佈assets 和 config
$ php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"
配置 .env 的db連線
檢查mysql的auto_increment_increment ,避免id兩個一跳造成 php artisan admin:install 報錯 // Menu::find(2)->roles()->save(Role::first()); // add role to menu. 查不到admin_menu.id = 2的資料,因為id跳到3
mysql> SHOW VARIABLES LIKE '%auto_increment_increment%';
如果是2,要改my.cnf改成1
然後你可以在 config/admin.php 配置 laravel-admin的路徑、db連線、table名字
跑以下命令完成安裝
$ php artisan admin:install
預設帳號:admin,密碼:admin
開管理員出現錯誤:
http://laravel.admin/admin/auth/users/create
Disk [admin] not configured, please add a disk config in `config/filesystems.php`
https://github.com/z-song/laravel-admin/issues/1327
http://laravel-admin.org/docs/#/en/model-form-upload?id=upload-to-local
config/filesystems.php 新增
'disks' => [
... ,
'admin' => [
'driver' => 'local',
'root' => public_path('uploads'),
'visibility' => 'public',
'url' => env('APP_URL').'/uploads', // 要改.env的 APP_URL为正确访问的网址
'
],
],
ps. laravel-admin會破圖的views是放在 vendor/encore/laravel-admin/resources/views/partials/sidebar.blade.php
為什麼 {{ Admin::user()->avatar }} 是取出完整網址,但db只存對應路徑?
vendor/encore/laravel-admin/src/Auth/Database/Administrator.php
Administrator的 getAvatarAttribute() 把它改了
return admin_asset('/vendor/laravel-admin/AdminLTE/dist/img/user2-160x160.jpg'); // 沒上傳頭像返回預設圖,預設圖不破圖
admin_asset() 如何運作?
在vendor/encore/laravel-admin/src/helpers.php 的 admin_asset()這裡
不要在config裡面用helpers
https://github.com/laravel/framework/issues/7671
這樣會造成 composer dumpautoload報錯
$ composer dumpautoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
In UrlGenerator.php line 111:
Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be
an instance of Illuminate\Http\Request, null given, called in /var/wwwroot
/project/vendor/laravel/framework/src/Illuminate/Routing/RoutingServicePro
vider.php on line 61
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
參考資料:
https://github.com/z-song/laravel-admin
沒有留言:
張貼留言