设置多个身份验证时出错-未定义的常量

时间:2019-02-13 10:22:41

标签: laravel

My code is:

public function up() 

{ 
    Schema::create('users', function (Blueprint $table) 
    { 

        $table->increments('id'); 
        $table->string('name'); 
        $table->string('email', 150)->unique(); 
        $table->string('username', 150)->unique(); 
        $table->timestamp('email_verified_at')->nullable(); 
        $table->boolean(‘isAdmin’)->nullable(); 
        $table->string('password', 150); $table->rememberToken(); 
        $table->timestamps(); }); 
}

Error in cmd Code / Migrations

有人可以帮助我吗? 我已经尝试将admin上的nullable切换为default(false),但这没用

3 个答案:

答案 0 :(得分:0)

首先,将您的代码放在此处而不是图像。将行更改为

$table->boolean('isAdmin')->nullable()

您必须使用引号。

答案 1 :(得分:0)

您在代码内使用了错误的引号,使用单引号'代替isAdmin上的`

public function up() 
{ 
    Schema::create('users', function (Blueprint $table) 
    { 

        $table->increments('id'); 
        $table->string('name'); 
        $table->string('email', 150)->unique(); 
        $table->string('username', 150)->unique(); 
        $table->timestamp('email_verified_at')->nullable(); 
        $table->boolean(‘isAdmin’)->nullable(); 
        $table->string('password', 150); $table->rememberToken(); 
        $table->timestamps(); }); 
}

更改此行

$table->boolean(‘isAdmin’)->nullable(); 

$table->boolean('isAdmin')->nullable(); 

答案 2 :(得分:-1)

请按照以下方式更新您的迁移文件:

    public function up() { 
      Schema::create('users', function (Blueprint $table) { 
         $table->increments('id'); 
         $table->string('name'); 
         $table->string('email', 150)->unique(); 
         $table->string('username', 150)->unique();       
         $table->timestamp('email_verified_at')->nullable(); 
         $table->boolean('isAdmin')->nullable(); 
         $table->string('password', 150); 
         $table->rememberToken(); 
         $table->timestamps(); 
       }); 
   } 

更新后的答案

public function up() { 
      Schema::create('users', function ($table) { 
         $table->increments('id'); 
         $table->string('name'); 
         $table->string('email', 150)->unique(); 
         $table->string('username', 150)->unique();       
         $table->timestamp('email_verified_at')->nullable(); 
         $table->boolean('isAdmin')->default(false);
         $table->string('password', 150); 
         $table->rememberToken(); 
         $table->timestamps(); 
       }); 
   } 

您的函数,例如:

public function index() { 
 return view('home'); 
}

public function admin() { 
 return view('admin'); 
}  

注意:主要更新迁移文件中的isAdmin字段