laravel实现用户的禁止登陆和禁止注册

你跑得慢,听到的是骂声,你跑得快,听到的就是风声。

禁止登录

app\Http\Controllers\Auth\LoginController.php
users表增加一个status字段,并重写两个方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
protected function attemptLogin(Request $request)
{
$request->merge([
'status' => true
]);
return $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
}

protected function credentials(Request $request)
{
return $request->only($this->username(), 'password', 'status');
}

禁止注册

app\Http\Controllers\Auth\RegisterController.php
修改前:

1
2
3
4
public function __construct()
{
$this->middleware('guest');
}

修改后:

1
2
3
4
public function __construct()
{
$this->middleware('auth');
}