Laravel8 安装 dcat/laravel-admin

Posted by

1.下载安装Laravel 8

composer create-project laravel/laravel laravel8 8

2. 安装完 laravel 之后需要修改.env 文件,设置数据库连接设置正确

3. 项目运行

php artisan serv

4.下载安装 dcat-admin

composer require dcat/laravel-admin:"2.2.0-beta"

5.然后运行下面的命令来发布资源:

  php artisan admin:publish
Copied Directory [/vendor/dcat/laravel-admin/database/migrations] To [/database/migrations]
Publishing complete.
Copied Directory [/vendor/dcat/laravel-admin/resources/dist] To [/public/vendor/dcat-admin]
Publishing complete.
Copied Directory [/vendor/dcat/laravel-admin/config] To [/config]
Publishing complete.
Copied Directory [/vendor/dcat/laravel-admin/resources/lang] To [/resources/lang]
Publishing complete.
Compiled views cleared!
You have new mail in /var/mail/yshuq

在该命令会生成配置文件 config/admin.php,可以在里面修改安装的地址、数据库连接、以及表名,建议都是用默认配置不修改。

6. 然后运行下面的命令完成安装:

php artisan admin:install
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (57.11ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (32.82ms)
Migrating: 2016_01_04_173148_create_admin_tables
Migrated:  2016_01_04_173148_create_admin_tables (309.79ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (24.03ms)
Migrating: 2020_09_07_090635_create_admin_settings_table
Migrated:  2020_09_07_090635_create_admin_settings_table (31.81ms)
Migrating: 2020_09_22_015815_create_admin_extensions_table
Migrated:  2020_09_22_015815_create_admin_extensions_table (61.20ms)
Migrating: 2020_11_01_083237_update_admin_menu_table
Migrated:  2020_11_01_083237_update_admin_menu_table (24.63ms)
Database seeding completed successfully.
Admin directory was created: /app/Admin
HomeController file was created: /app/Admin/Controllers/HomeController.php
AuthController file was created: /app/Admin/Controllers/AuthController.php
Bootstrap file was created: /app/Admin/bootstrap.php
Routes file was created: /app/Admin/routes.php
Done.
You have new mail in /var/mail/yshuq

上述步骤操作完成之后就可以配置 web 服务了,注意需要把 web 目录指向 public 目录!如果用的是 nginx,还需要在配置中加上伪静态配置

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

启动服务后,在浏览器打开 http://localhost/admin,使用用户名 admin 和密码 admin 登陆。

在我这里执行的操作是:

php artisan serv
Starting Laravel development server: http://127.0.0.1:8000
[Wed Jun 22 17:57:22 2022] Failed to listen on 127.0.0.1:8000 (reason: Address already in use)
Starting Laravel development server: http://127.0.0.1:8001

登录后台:http://127.0.0.1:8000/admin admin admin

登录进去看见这个界面,则代表安装成功了。

dcat admin 后台

配置文件

安装完成之后,dcat-admin 所有的配置都在 config/admin.php 文件中。

安装完成之后,后台的安装目录为 app/Admin,之后大部分的后台开发编码工作都是在这个目录下进行。

dcat-admin

app/Admin/routes.php 文件用来配置后台路由。
app/Admin/bootstrap.php 是 dcat-admin 的启动文件,使用方法请参考文件里面的注释.
app/Admin/Controllers 目录用来存放后台控制器文件,该目录下的 HomeController.php 文件是后台首页的显示控制器,AuthController.php 为后台管理员登录鉴权控制器。
app/Admin/Metrics/Examples 里面存放的是数据统计卡片(Metric Card) 的示例代码.

静态文件
后台所需的前端静态文件在 /public/vendor/dcat-admin 目录下。

数据表迁移文件
对应的数据表迁移文件在 /database/migrations 目录下。

语言包
语言包文件在 /resources/lang