注册
/app/Http/Controller/Auth/RegisterController.php
middleware('guest'); } /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data) { return Validator::make($data, [ //'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:100', 'unique:users'],// 'password' => ['required', 'string', 'min:8', 'confirmed'], 'password' => ['required', 'string', 'min:8'], ]); } /** * Create a new user instance after a valid registration. * * @param array $data * @return \App\User */ protected function create(array $data) { return User::create([ 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); } protected function registered(Request $request) { return $request->ajax() ? response()->json('success') : redirect($this->redirectPath()); }}
其中
use App\Models\User; 需要修改为自己的模型
use Illuminate\Http\Request; 添加
protected $redirectTo = '/'; 修改为注册成功后跳转的URL
return Validator::make 根据自己的字段进行修改
在最后添加
protected function registered(Request $request) { return $request->ajax() ? response()->json('success') : redirect($this->redirectPath()); }
登录
/app/Http/Controller/Auth/LoginController.php
middleware('guest')->except('logout'); } protected function authenticated(Request $request) { return $request->ajax() ? response()->json('success') : redirect($this->redirectPath()); }}
其中
use Illuminate\Http\Request; 添加
在底部添加
protected function authenticated(Request $request) { return $request->ajax() ? response()->json('success') : redirect($this->redirectPath()); }