-1
我的需求只是Laravel驗證規則。我想使用Laravel驗證來檢查變量。並通過控制器返回字符串顯示自定義錯誤(我不使用視圖,刀片,會議,...我只是返回字符串)Laravel驗證規則
if(strlen($username) < 4) return '{"r": "US","msg": "username is short"}';
if(strlen($username) > 64) return '{"r": "UL","msg": "username is long"}';
if(strlen($address) > 200) return '{"r": "A","msg": "wrong address"}';
我想是這樣的:
if($validation->username->min has error)
return 'string:username is short';
if($validation->address->max has error)
return 'string:address is long';
if($validation->username->unique has error)
return 'string:username already exists';
我知道了。但我想要的東西像這樣︰if($ validator-> errors() - > has('username') - > has('max')){//用戶名最大字段無效 –
@xray_我已更新我的答案。 –