Laravel – admin 的安装

Posted by

Laravel-admin 的安装

首先确保安装好了laravel,并且数据库连接设置正确。

composer require encore/laravel-admin:1.*

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

php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"

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

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

php artisan admin:install
yshuqdeMacBook-Pro:laravel5 yshuq$ composer require encore/laravel-admin:1.*
./composer.json has been updated
Running composer update encore/laravel-admin
Loading composer repositories with package information
Updating dependencies
Lock file operations: 8 installs, 0 updates, 0 removals
  - Locking doctrine/cache (2.1.1)
  - Locking doctrine/dbal (3.3.2)
  - Locking doctrine/deprecations (v0.5.3)
  - Locking doctrine/event-manager (1.1.1)
  - Locking encore/laravel-admin (v1.8.17)
  - Locking psr/cache (1.0.1)
  - Locking symfony/deprecation-contracts (v2.5.0)
  - Locking symfony/dom-crawler (v5.4.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 8 installs, 0 updates, 0 removals
  - Installing doctrine/cache (2.1.1): Extracting archive
  - Installing doctrine/deprecations (v0.5.3): Extracting archive
  - Installing doctrine/event-manager (1.1.1): Extracting archive
  - Installing symfony/deprecation-contracts (v2.5.0): Extracting archive
  - Installing symfony/dom-crawler (v5.4.3): Extracting archive
  - Installing psr/cache (1.0.1): Extracting archive
  - Installing doctrine/dbal (3.3.2): Extracting archive
  - Installing encore/laravel-admin (v1.8.17): Extracting archive
3 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Package mtdowling/cron-expression is abandoned, you should avoid using it. Use dragonmantank/cron-expression instead.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
Carbon 1 is deprecated, see how to migrate to Carbon 2.
https://carbon.nesbot.com/docs/#api-carbon-2
    You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: encore/laravel-admin
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Package manifest generated successfully.
46 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
yshuqdeMacBook-Pro:laravel5 yshuq$ php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"
Copied Directory [/vendor/encore/laravel-admin/config] To [/config]
Copied Directory [/vendor/encore/laravel-admin/resources/lang] To [/resources/lang]
Copied Directory [/vendor/encore/laravel-admin/database/migrations] To [/database/migrations]
Copied Directory [/vendor/encore/laravel-admin/resources/assets] To [/public/vendor/laravel-admin]
Publishing complete.
yshuqdeMacBook-Pro:laravel5 yshuq$ php artisan admin:install
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
Migrating: 2016_01_04_173148_create_admin_tables
Migrated:  2016_01_04_173148_create_admin_tables
Admin directory was created: /app/Admin
HomeController file was created: /app/Admin/Controllers/HomeController.php
AuthController file was created: /app/Admin/Controllers/AuthController.php
ExampleController file was created: /app/Admin/Controllers/ExampleController.php
Bootstrap file was created: /app/Admin/bootstrap.php
Routes file was created: /app/Admin/routes.php
yshuqdeMacBook-Pro:laravel5 yshuq$
Notice

运行这个命令的时候,如果遇到了下面的错误:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter tableusersadd uniqueusers_email_unique(email))

参考这个issue来解决 https://github.com/z-song/laravel-admin/issues/1541

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

生成的文件

安装完成之后,会在项目目录中生成以下的文件:

配置文件

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

后台项目文件

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

app/Admin
├── Controllers
│   ├── ExampleController.php
│   └── HomeController.php
├── bootstrap.php
└── routes.php

app/Admin/routes.php文件用来配置后台路由。

app/Admin/bootstrap.php 是laravel-admin的启动文件, 使用方法请参考文件里面的注释.

app/Admin/Controllers目录用来存放后台控制器文件,该目录下的HomeController.php文件是后台首页的显示控制器,ExampleController.php为实例文件。

静态文件

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