[TOC]
# 安裝
## 文檔地址
[https://learnku.com/docs/laravel/5.8](https://learnku.com/docs/laravel/5.8)
[https://laravel.com/docs/5.8](https://laravel.com/docs/5.8)
[Laravel 開發環境部署](https://learnku.com/docs/laravel-development-environment/5.8)
## 環境要求
```
PHP >= 7.1.3
OpenSSL PHP 拓展
PDO PHP 拓展
Mbstring PHP 拓展
Tokenizer PHP 拓展
XML PHP 拓展
Ctype PHP 拓展
JSON PHP 拓展
BCMath PHP 拓展
```
## Composer安裝
```
$ composer create-project --prefer-dist laravel/laravel blog "5.8.*"
```
## 環境文件 .env
```
// 設置應用、調試、數據庫、Redis、郵件等
MAIL_MAILER=smtp
MAIL_HOST=smtp.xxx.com
MAIL_PORT=465
MAIL_USERNAME=xxx@xxx.com
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=xxx@xxx.com
MAIL_FROM_NAME="${APP_NAME}"
```
## 配置文件 config/app.php
```
// 時區配置
'timezone' => 'PRC',
/**
* 在調試頁面隱藏環境變量
*/
'debug_blacklist' => [
'_ENV' => [
'APP_KEY',
'DB_PASSWORD',
'REDIS_PASSWORD',
'MAIL_PASSWORD',
],
'_SERVER' => [
'APP_KEY',
'DB_PASSWORD',
'REDIS_PASSWORD',
'MAIL_PASSWORD',
],
'_POST' => [
'password',
],
],
```
## 獲取環境變量與配置
```
// 獲取環境變量,第二參數設置默認值
$env = env('APP_NAME', 'Laravel');
// 確定當前環境
$environment = App::environment();
if (App::environment('local')) {
// 當前環境是 local
}
if (App::environment(['local', 'staging'])) {
// 當前的環境是 local 或 staging...
}
// 獲取配置值
$value = config('app.timezone');
// 設置配置值
config(['app.timezone' => 'America/Chicago']);
```
## 存儲目錄
```
// storage/app/public 生成軟鏈接 public/storage
$ php artisan storage:link
```
## 生成自定義錯誤模板頁面
```
// 保存目錄 resources/views/errors
$ php artisan vendor:publish --tag=laravel-errors
```
## 語言擴展包
```
$ composer require laravel-lang/lang:~4.0
// 將 vendor/laravel-lang/lang/src 文件夾下的語言包復制到 resources/lang/
// 將 vendor/laravel-lang/lang/json 文件夾下的語言json復制到 resources/lang/
// 更新配置 config/app.php,不生效檢查是否生成配置緩存
'locale' => 'zh-CN',
```
## Redis擴展包
```
$ composer require predis/predis
```
## 開發擴展包
```
// https://packagist.org/ 查看適用版本
// https://github.com/barryvdh/laravel-debugbar
$ composer require barryvdh/laravel-debugbar=3.4.2 --dev
// 生成配置文件,存放位置 config/debugbar.php
$ php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
// 在 config/debugbar.php 配置開關
'enabled' => env('APP_DEBUG', false),
// 使用方法
app('debugbar')->info('test');
\Debugbar::info('test');
use Barryvdh\Debugbar\Facade as Debugbar;
Debugbar::info('test');
// https://github.com/barryvdh/laravel-ide-helper
$ composer require barryvdh/laravel-ide-helper=2.8.0 --dev
// 生成 Facades 注釋,存在位置為根目錄 _ide_helper.php
$ php artisan ide-helper:generate
```
## 構建認證系統
```
// Laravel > 5.8 不適用,請查看高版本文檔
$ php artisan make:auth
$ php artisan migrate
```
- 入門指南
- 安裝
- 部署
- 基礎功能
- 路由
- 中間件
- CSRF 保護
- 控制器
- 請求
- 響應
- 視圖
- URL
- Session
- 表單驗證
- 錯誤
- 日志
- 前端開發
- Blade 模板
- 本地化
- 腳手架
- 編譯資源 Mix
- 安全相關
- 用戶認證
- API 認證
- 綜合話題
- 命令行
- 廣播
- 緩存
- 集合
- 事件
- 文件存儲
- 輔助函數
- 郵件發送
- 消息通知
- 擴展包開發
- 隊列
- 任務調度
- 數據庫
- 快速入門
- 查詢構造器
- 分頁
- 數據庫遷移
- 數據填充
- Redis
- Eloquent ORM
- 快速入門
- 速查表
- Artisan
- Auth
- Blade
- Cache
- Collection
- Composer
- Config
- Container
- Cookie
- DB
- Environment
- Event
- File
- Helper
- Input
- Lang
- Log
- Model
- Pagination
- Queue
- Redirect
- Request
- Response
- Route
- SSH
- Schema
- Security
- Session
- Storage
- String
- URL
- UnitTest
- Validation
- View