[英]Login in Laravel 5.8
I am beginner in Laravel.我是 Laravel 的初学者。 I use in my project Laravel 5.8.
我在我的项目中使用 Laravel 5.8。
I use Laravel login system in my project.我在我的项目中使用 Laravel 登录系统。
I have my user migration:我有我的用户迁移:
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->char('enable', 1)->default(0);
$table->char('demo_mode', 1)->default(0);
$table->date('account_paid_for');
$table->string('name', 120)->nullable();
$table->string('surname', 120)->nullable();
$table->string('email', 120)->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('url_address', 160);
$table->text('content')->nullable();
$table->dateTime('last_activity')->nullable();
$table->rememberToken();
$table->timestamps();
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
I need to change Laravel's default login to verify that enable = 1我需要更改 Laravel 的默认登录名以验证 enable = 1
Only users with enable = 1 can log in. How to do it只有 enable = 1 的用户才能登录。 怎么做
You can add an after middleware or just override the authenticated method within your LoginController:你可以添加一个 after 中间件或者只是在你的 LoginController 中覆盖经过身份验证的方法:
use Auth; // add this at the top
protected function authenticated( Request $request, $user )
{
if( ! $user->enable) {
Auth::logout(); // log out the user
return back()->with('error', 'The user is not allowed to enter');
}
return redirect($this->redirectTo);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.