我刚刚在Laravel默认用户表中添加了一个新列[role_id]:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddRolesidToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('role_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('role_id');
});
}
}
我不知道Laravel在哪里可以为用户添加验证规则?
例如,如果用户没有必需的role_id,即使他在数据库中,也无法登录! 所以我们的想法是管理员应首先激活帐户,以便用户登录。
答案 0 :(得分:1)
请参阅文档中的Manually Authenticating Users部分。我们可以在身份验证上指定其他条件:
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
// The user is active, not suspended, and exists.
}