The code has been put on Github, welcome to refer to and propose issue: laravel-quick-start Github address
Environment + package
Total packages to install
// There is no need to manually import a service provider"arcanedev/log-viewer": "^ 4.3", // There is no need to import service providers manually"barryvdh/laravel-debugbar": "^ 2.4", // There is no need to import service providers manually"encore/laravel-admin": "1.4. *", // There is no need to import service providers manually"laracasts/flash": "^ 3.0", // There is no need to import service providers manually"predis/predis": "^ 1.1", // There is no need to import service providers manually"prettus/l5-repository": "^ 2.6", // There is no need to import service providers manually"zgldh/qiniu-laravel-storage": "^ 0.7.0"// There is no need to manually import a service provider"spatie/laravel-backup": "^ 4.18", // There is no need to import service providers manually"intervention/image": "^ 2.4", // There is no need to import service providers manually"maatwebsite/excel": "^ 2.1"// Install it directly"doctrine/dbal": "^ 2.5"// Install it directly"spatie/eloquent-sortable": "^ 3.3", / * * * tian, introducing ` axdlee/laravel - config - writer ` - can generate configuration files 】 【 don't * / axdlee \ config \ ConfigServiceProvider: : class,"axdlee/laravel-config-writer": "^ 1.0"."hassankhan/config": "^ 0.10.0".Copy the code
Initialize the project
Laravel New project nameCopy the code
Modify the time zone
Change the time zone in config/app.php
'timezone'= >'UTC'Instead,'timezone'= >'RPC'.Copy the code
willsession
There areredis
中
-
Composer require predis/predis
-
Add redis in config\database.php
// tian add session saved to redis
'session'= > ['host' => env('REDIS_HOST'.'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database'= > 1,].Copy the code
- in
config\session.php
Changes in the
// tian add session saved to redis
// 'connection' => null,
'connection'= >'session'.Copy the code
- in
.env
Modify the inside
# tian add session saved to redis
SESSION_DRIVER=redis
Copy the code
Introduce custom classes and functions
Introduce custom classes
Create the Classes folder under the app directory
It should have been introduced in composer. Json, but it is not needed because it is in app directory pSR-4
"autoload": {
"classmap": [
"database"."app/Classes"// This line introduces the custom class],"psr-4": {
"App\\": "app/"
},
"files": [
"app/helpers.php"// this line, introduce custom function]},Copy the code
Introduce custom functions
Create a new file called helpers.php in your app directory
uselaravel-admin
-
Install Composer require encore/laravel-admin
-
Then run the following command to publish the resource: PHP artisan vendor:publish –provider=”Encore Admin AdminServiceProvider”
-
Custom (overload) Change the default 9 tables to the database in config/admin.php with the laravel_ prefix.
-
To prevent data migration errors, resolve the character length problem first
-
Install 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
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
Copy the code
- Configure pictures Upload pictures, configure
config/filesystems.php
'admin'= > ['driver'= >'local'.'root' => public_path('uploads'),
'visibility'= >'public'.'url' => env('APP_URL').'/uploads',].Copy the code
- Custom view directories
Copy vendor/encore/laravel-admin/resources/views to the project’s resources/views/laravel-admin and add the code to app/ admin/ bootstrap.php: app(‘view’)->prependNamespace(‘admin’, resource_path(‘views/laravel-admin’));
- Custom language packs
Copy vendor/encore/laravel-admin/lang to the project’s resources/lang/laravel-admin and add the code to app/ admin/ bootstrap.php: app(‘translator’)->addNamespace(‘admin’, resource_path(‘lang/laravel-admin’));
/** * Ignore 'map', 'editor' control */ Encore\Admin\Form::forget(['map'.'editor']); /** * change the namespace */ / tian changes the 'laravel-admin' view to make it easier to change, so that there is no need to move the source code of 'laravel-admin'. Copy 'vendor/encore/laravel-admin/views' to project's' resources/views/laravel-admin 'app('view')->prependNamespace('admin', resource_path('views/laravel-admin')); // Tian modifies the language package of 'laravel-admin' and copies' vendor/encore/laravel-admin/lang 'into the project's' resources/lang/admin '. If you set the locale to 'zh-cn', rename the 'zh_CN' directory in the 'resources/lang/admin' directory to 'zh-cn'.'translator')->addNamespace('admin', resource_path('lang/laravel-admin'));
Copy the code
laravel-admin
Changes to be made:
#### Custom (overload)
##### Change the default nine tables
The database table name in config/admin.php is prefixed with laravel_
##### About custom views
Copy vendor/encore/laravel-admin/resources/views to the project’s resources/views/laravel-admin and add the code to app/ admin/ bootstrap.php:
app('view')->prependNamespace('admin', resource_path('views/laravel-admin'));
Copy the code
Laravel-admin: resources/views/admin: resources/views/admin: resources/views/admin You need to copy vendor/encore/laravel-admin/views into the resources/views/admin folder of the project.
##### Setting language
After the installation, the default language is En. To use Chinese, open config/app.php and set the locale to zh-cn.
##### Custom language
If you need to modify the laravel-admin language package, you can do this by copying vendor/encore/laravel-admin/lang to the project’s resources/lang/admin. Then add the code to the app/Admin/bootstrap.php file:
app('translator')->addNamespace('admin', resource_path('lang/admin'));
Copy the code
If the locale of the system language is zh-cn, rename the zh_CN directory in the resources/lang/admin directory to zh-cn. When updating laravel-admin, change the name accordingly.
##### Updates static resources
If some components fail to work properly after update, it may be that the static resources of Laravel-admin have been updated, so you need to manually override public/packages with static resources of Vendor/Encore /laravel-admin/assets Don’t forget to clean the browser cache after overwriting static resource files in the directory.
##### Customize the login page and login logic
In the routing file app/Admin/routes.php, you can override the routes on the login page and logic to realize the customized functions
Route::group([
'prefix' => config('admin.prefix'),
'namespace' => Admin::controllerNamespace(),
'middleware'= > ['web'.'admin']],function (Router $router) {
$router->get('auth/login'.'AuthController@getLogin');
$router->post('auth/login'.'AuthController@postLogin');
});
Copy the code
Implement your own login page and login logic in the getLogin and postLogin methods of the custom router AuthController.
Using log packagesarcanedev/log-viewer
-
composer require arcanedev/log-viewer
-
Service providers are introduced automatically, so there is no need to add providers
-
php artisan log-viewer:publish
__ _ / / ___ __ _ / \ / (_) _____ _____ _ __ / / / _ \ / _ ` \ \ / / | / _ \ \ / / / / _ \'__| / /__| (_) | (_| |\ V /| | __/\ V V / __/ | \____/\___/ \__, | \ | / _ _ | \ ___ | \ _ \ _ / \ ___ _ - | | | ___ / Version 4.5.1 - Created by ARCANEDEV � Copied the File [\vendor\arcanedev\log-viewer\config\log-viewer.php] To [\config\log -viewer.php] Copied Directory [\vendor\arcanedev\log-viewer\resources\views] To [\resources\v iews\vendor\log-viewer] Copied Directory [\vendor\arcanedev\log-viewer\resources\lang] To [\resources\la ng\vendor\log-viewer] Publishing complete.Copy the code
- Changing a Log Level
Env LOG_CHANNEL=stack to daily
Laravel5.5 and before:'log' => env('APP_LOG'.'single'),
'log_level' => env('APP_LOG_LEVEL'.'debug'),
Copy the code
- Change the language
Set locale=’auto’ in config/ log-view.php to’ en ‘
- Modify routing and middleware
'route'= > ['enabled'= >true.'attributes'= > [/ /'prefix'= >'log-viewer'// Change the route prefix'prefix'= >'admin/log-viewer', / /'middleware' => env('ARCANEDEV_LOGVIEWER_MIDDLEWARE')? explode(', ', env('ARCANEDEV_LOGVIEWER_MIDDLEWARE')) : Null, // Modify middleware, or change directly in '. Env 'to: ARCANEDEV_LOGVIEWER_MIDDLEWARE=web,admin,admin.bootstrap,admin.pjax,admin.log,admin.bootstrap,admin.permission'middleware'= > ['web'.'admin'.'admin.bootstrap'.'admin.pjax'.'admin.log'.'admin.bootstrap'.'admin.permission'],]],Copy the code
- access
The original link: http://127.0.0.1:8000/log-viewer
After the change routing prefix: http://127.0.0.1:8000/admin/log-viewer
Using debugging packagesbarryvdh/laravel-debugbar
-
composer require barryvdh/laravel-debugbar
-
Barryvdh\Debugbar\ServiceProvider::class,
-
‘Debugbar’ => Barryvdh\Debugbar\Facade::class,
-
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
Copied File [\vendor\barryvdh\laravel-debugbar\config\debugbar.php] To [\config\
debugbar.php]
Publishing complete.
Copy the code
- In a non-debugging environment, disable the debug function
.env=true
Instead of.env=false
By default, debug is enabled.
Database Backupspatie/laravel-backup
-
composer require spatie/laravel-backup
-
Automatic introduction of service providers
-
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
Copied File [\vendor\spatie\laravel-backup\config\backup.php] To [\config\backup
.php]
Copied Directory [\vendor\spatie\laravel-backup\resources\lang] To [\resources\l
ang\vendor\backup]
Publishing complete.
Copy the code
-
To use this package, you need to install Composer Require guzzleHTTP /guzzle because requests are needed
-
If you want to back up to a custom directory, you can perform the following configuration
app/config/filesystems.php:
'disks'=> [// Add the laravel-backup directory'backup'= > ['driver'= >'local'.'root' => env('BACKUP_PATH'),
'visibility'= >'public',]],Copy the code
app/config/laravel-backup.php:
'destination' => [
/*
* The disk names on which the backups will be stored.
*/
'disks'= > [/ /'local'.'backup', / /'admin',]],Copy the code
- The command that
To back up to a specific disk instead of all disks, run:
php artisan backup:run --only-to-disk=name-of-your-disk
Copy the code
Backup files and databases:
php artisan backup:run
Copy the code
Only backup db:
php artisan backup:run --only-db
Copy the code
Backup files only:
php artisan backup:run --only-files
Copy the code
Clean backup:
php artisan backup:clean
Copy the code
View the status of all monitored target file systems:
php artisan backup:list
Copy the code
'monitorBackups' => [
[
'name' => config('app.name'),
'disks'= > ['local'].'newestBackupsShouldNotBeOlderThanDays'= > 1,'storageUsedMayNotBeHigherThanMegabytes'=> 5000,], /* ['name'= >'name of the second app'.'disks'= > ['local'.'s3'].'newestBackupsShouldNotBeOlderThanDays'= > 1,'storageUsedMayNotBeHigherThanMegabytes'=> 5000,], */],Copy the code
Introduce custom routes -(because code is automatically spit out, routes are subdirectory)
Load the routes in the routes/web folder
In the app/will/RouteServiceProvider. PHP
In the map() method, add the following code:
// tian add `mapCustomRoutes`
$this->mapCustomRoutes();
Copy the code
The following methods are added:
/**
* tian add
* Define the "Custom" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapCustomRoutes() {/** * load routes/web folder */ Route::group([// 'laravel-admin' middleware)'admin.auth'.'admin.pjax'.'admin.log'.'admin.bootstrap'.'admin.permission'
'middleware'= > ['web'.'admin'.'admin.bootstrap'.'admin.pjax'.'admin.log'.'admin.bootstrap'.'admin.permission'].'namespace'= >'App\Http\Controllers'.'prefix'= >'admin',].function ($router) {
$routePath = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'routes' . DIRECTORY_SEPARATOR . 'web';
$this->getFilePath($routePath); }); } /** * [getFilePath recursively traverses the file] * @param string$path [description]
* @return [type] [description]
*/
protected function getFilePath($path = '. 'Opendir () returns a directory handle, on failurefalse
$current_dir = opendir($path); // readdir() returns an entry in the open directory handlewhile (($file = readdir($current_dir))! = =false) {// Build subdirectory paths$sub_dir = $path . DIRECTORY_SEPARATOR . $file;
if ($file= ='. ' || $file= ='.. ') {
continue; // If it is a directory, recurse}else if (is_dir($sub_dir)) {
$this->getFilePath($sub_dir);
} else {
if (is_dir($sub_dir)) {
$this->getFilePath($sub_dir);
}
if (is_file($sub_dir)) {
require_once $sub_dir; } // If it is a file, just print //$path = substr($path, strrpos($path.'routes'));
// echo base_path($path . DIRECTORY_SEPARATOR . $file).'<br />';
// require base_path($path . DIRECTORY_SEPARATOR . $file); }}}Copy the code
Install the database abstraction layerprettus/l5-repository
[A layer of encapsulation of the model]
-
composer require prettus/l5-repository
-
Automatic introduction of service providers
-
php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositoryServiceProvider"
Copied File [\vendor\prettus\l5-repository\src\resources\config\repository.php]
To [\config\repository.php]
Publishing complete.
Copy the code
Installation Tips packagelaracasts/flash
[Prompt box]
-
composer require laracasts/flash
-
Need to import service providers [no longer needed, automatic import of service providers after Laravel5.5]
-
Add Facades to aliases in config/app.php
The prompt can be displayed in the Laravel-admin framework
Add the following code to
{{-- tian add flash --}}
@include('flash::message')
Copy the code
Doctrine/dbal 【 usemigration
As a database version control tool, you need to introduce additional data when you need to make changes to existing data tablesdoctrine/dbal
Extension. 】
composer require doctrine/dbal
Install the image processing packageintervention/image
-
composer require intervention/image
-
Automatic introduction of service providers
-
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
Copied File [\vendor\intervention\image\src\config\config.php] To [\config\image
.php]
Publishing complete.
Copy the code
requestguzzlehttp/guzzle
Send an HTTP request
composer require guzzlehttp/guzzle
Seven NiuYunzgldh/qiniu-laravel-storage
[Optional installation]
-
composer require zgldh/qiniu-laravel-storage
-
Automatic introduction of service providers
Excel to deal withmaatwebsite/excel
[Optional installation]
-
composer require maatwebsite/excel
-
Automatic introduction of service providers
-
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"
Model sortspatie/eloquent-sortable
[Optional installation]
composer require spatie/eloquent-sortable
The problem
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
MySql supports utF8 encoding with a maximum length of 3 bytes. If the utF8 encoding is 4 bytes wide, an insert exception will occur. The maximum Unicode character that a three-byte UTF-8 can encode is 0xFFFF, the basic Multiliteral plane (BMP) in Unicode. Therefore, non-basic multilingual Unicode characters including Emoji (Emoji is a special Unicode encoding) cannot be stored using MySql utF8 character set.
This is probably one of the reasons Laravel 5.4 switched to 4-byte UTF8MB4 character encoding. Note, however, that utF8MB4 encoding is only supported after MySql 5.5.3.
Solution: AppServiceProvider invokes the Schema: : defaultStringLength ways to implement configuration
use Illuminate\Support\Facades\Schema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
Copy the code
- Question 2Use:
laravel new yunjuji-generator
An errorScript "post-install-cmd" is not defined in this package
Composer global update/Composer global require “laravel/ Installer”