## Validation
~~~php
Validator::make(
array('key' => 'Foo'),
array('key' => 'required|in:Foo')
);
Validator::extend('foo', function($attribute, $value, $params){});
Validator::extend('foo', 'FooValidator@validate');
Validator::resolver(function($translator, $data, $rules, $msgs)
{
return new FooValidator($translator, $data, $rules, $msgs);
});
~~~
### 驗證規則
~~~php
accepted // 待驗證字段必須是 yes , on ,1 或 true
active_url
after:YYYY-MM-DD // 待驗證字段必須是給定的日期之后的值對應的日期。
// 待驗證字段必須是給定的日期之前的值對應的日期。
before:YYYY-MM-DD
alpha // 待驗證字段只能由字母組成。
alpha_dash // 待驗證字段可能包含字母、數字,短破折號(-)和下劃線(_)。
alpha_num // 待驗證字段只能由字母和數字組成。
array // 待驗證字段必須是有效的 PHP 數組。
between:1,10 // 驗證字段的大小必須在給定的 min 和 max 之間。字符串、數字、數組和文件的計算方式都使用size方法
confirmed // 驗證字段必須具有匹配字段 foo_confirmation
date // 根據 PHP strtotime 函數,驗證的字段必須是有效的日期。
date_format:YYYY-MM-DD // 驗證字段必須匹配給定的日期格式。
different:fieldname // 驗證的字段值必須與字段 field 的值不同。
digits:value // 驗證的字段必須為 numeric ,并且必須具有確切長度 _value_。
digits_between:min,max // 驗證中的字段必須為數字,并且長度必須在給定的 min 和 max 之間。
boolean // 驗證的字段必須可以轉換為 Boolean 類型。
email // 驗證的字段必須符合 e-mail 地址格式。
// 驗證的字段必須存在于給定的數據庫表中。
exists:table,column
image // 驗證的文件必須是圖片 (jpeg, png, bmp, gif, svg, or webp)
in:foo,bar,... // 驗證字段必須包含在給定的值列表中。
not_in:foo,bar,... // 驗證字段不能包含在給定的值的列表中
integer // 驗證的字段必須是整數。
numeric // 驗證字段必須為數值。
ip // 驗證的字段必須是 IP 地址。
max:value // 驗證中的字段必須小于或等于 value。字符串、數字、數組或是文件大小的計算方式都用 size規則。
min:value // 驗證中的字段必須小于或等于 value。同 max
mimes:jpeg,png // 驗證的文件必須具有與列出的其中一個擴展名相對應的 MIME 類型。
regex:[0-9] // 驗證字段必須與給定的正則表達式匹配。
required // 驗證的字段必須存在于輸入數據中,而不是空。
required_if:field,value
required_with:foo,bar,...
required_with_all:foo,bar,...
required_without:foo,bar,...
required_without_all:foo,bar,...
same:field // 驗證字段的值必須與給定字段的值相同。
size:value // 驗證字段必須與給定值的大小一致。字符串(字符數),數字(數值),數組(count),文件(kb)
timezone // 驗證字段必須為符合 timezone_identifiers_list 所定義的有效時區標識。
unique:table,column,except,idColumn // 驗證字段在給定的數據庫表中必須是唯一的。
url // 驗證的字段必須是有效的 URL。
~~~
- 參考知識--非必學僅供必要時候查詢
- 知識清單
- Composer 安裝等
- artisan--創建模型-控制器-各種模塊
- Route--路由
- Paginate--分頁
- File--文件
- View--視圖
- template--模版
- Model--模型
- Schema--數據表索引-外鍵-字段類型
- DB-基本使用-查詢語句-joins-聚合--原生sql-增刪改查等
- message--消息
- Validation--驗證規則
- Auth-用戶認證-用戶權限
- Helper-數組對象-路徑-字符串-urls-links等
- Session會話
- Response--回應
- Request--請求
- Redirect--重定向
- Environment--環境
- Log--日志
- URL--地址
- Event--事件
- Input--輸入
- Security安全--哈希-加密解密
- Queue--監聽
- Container--容器
- Config--參數設置
- Cache--緩存
- Cookie--設置-獲取--刪除等
- Mail--郵件
- String--字符串
- Collection--集合
- Storage--存儲
- Lang--語言
- 單元測試
- 文件夾結構簡介
- 第一章 laravel8運行環境的搭建(已經有了運行環境的直接跳過)