class LoginController extends Controller { protected function validateLogin(\App\Http\Requests $request) { $request->validate([ 'username' => 'required|string', 'password' => 'required|string', 'captcha' => ['required', 'captcha'], ], [ 'captcha.required' => '验证码不能为空', 'captcha.captcha' => '请输入正确的验证码', ]); } }
class UserRequest extends FormRequest { public function rules() { return [ // 'name' => 'required|between:3,25|regex:/^[a-zA-Z0-9\-\_]+$/|unique:users,name,'.Auth::id(), 'email' => 'required|email', 'introduction' => 'max:80', ]; } public function messages() { return [ 'name.required' => '用户名不能为空', 'name.regex' => '用户名只能是字母和数字', 'name.unique' => '用户名已存在', 'name.between' => '用户名长度需要3~25个字符', ]; } } class LoginController extends Controller { public function update(\App\Http\Requests\UserRequest $request, User $user) { // } }