-2
我對這個控制器沒有看法。我想使用Laravel驗證來檢查變量。並通過控制器返回字符串顯示自定義錯誤(我不使用視圖,刀片,會議,...我只是返回字符串)Laravel 5.2驗證控制器
if(strlen($username) < 4) return '{"r": "US","msg": "username is short"}';
if(strlen($username) > 64) return '{"r": "UL","msg": "username is long"}';
if(preg_match("/(\S*\d+\S*[[:alpha:]]+\S*)|(\S*[[:alpha:]]+\S*\d+\S*)/", $password)) return '{"r": "P","msg": "wrong password"}';
if(strlen($name) > 32) '{"r": "N","msg": "wrong name"}';
if(strlen($address) > 200) '{"r": "A","msg": "wrong address"}';
我想是這樣的:
'username' => 'required|min:4|max:64|unique:users|regex:/[a-zA-Z]+[a-zA-Z0-9_]*/',
'email' => 'required|unique:users|email|min:8',
...
Tanx。但是我怎麼能理解哪個變量有錯誤或者是什麼錯誤? –