播种时使用未定义的常量

jkjmr6

当尝试使用php artisan db:seed为数据库播种时,出现此错误

[ErrorException] Use of undefined constant username - assumed 'username'

我检查了Laravel文档,语法看起来正确,但是我不确定我在搞砸什么。

<?php

class DatabaseSeeder extends Seeder {

/**
 * Run the database seeds.
 *
 * @return void
 */
public function run(){
    Eloquent::unguard();

    $this->call('UsersTableSeeder');
  }

}


class UsersTableSeeder extends Seeder {

public function run(){
    User::create([
        'username'  => 'Ziggy',
        'email'     => '[email protected]',
        'password'  =>  '1234'
    ]);
  }
}

编辑:我添加了用户模型:

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    public $timestamps = false;
    protected $fillable = [username, password];

    use UserTrait, RemindableTrait;

    /**
    * The database table used by the model.
    *
    * @var string
    */
    protected $table = 'users';

    /**
    * The attributes excluded from the model's JSON form.
    *
    * @var array
    */
    protected $hidden = array('password', 'remember_token');

}

这是使用的迁移文件:

<?php

   use Illuminate\Database\Schema\Blueprint;
   use Illuminate\Database\Migrations\Migration;

   class CreateUsersTable extends Migration {

   /**
    * Run the migrations.
    *
    * @return void
    */
   public function up()
   {
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('username');
        $table->string('email')->unique();
        $table->string('password');
        $table->timestamps();
    });
  }

   /**
   * Reverse the migrations.
   *
   * @return void
   */
   public function down()
   {
       Schema::table('users', function(Blueprint $table)
       {
            Schema::drop('users');
        });
    }

}
马卡努伊

在用户类中,更改以下内容:

protected $fillable = [username, password];

对此

protected $fillable = ['username', 'password'];

声明方式,PHP将它们视为常量而不是字符串

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

播种时使用未定义的常量

来自分类Dev

PHP使用未定义的常量

来自分类Dev

在日期上使用未定义的常量

来自分类Dev

PHP使用未定义的常量错误

来自分类Dev

Codeigniter消息:使用未定义的常量

来自分类Dev

使用未定义的常量 id - 假设

来自分类Dev

接受使用未定义的常量

来自分类Dev

使用未定义的常量数据

来自分类Dev

PHP:定义它时未定义的常量

来自分类Dev

laravel 播种返回未定义的索引

来自分类Dev

注意:对已定义的变量使用未定义的常量

来自分类Dev

PHP常量未定义

来自分类Dev

使用未定义的常量MCRYPT_BLOWFISH

来自分类Dev

Laravel中的“使用未定义的常量...”错误

来自分类Dev

Laravel View Composer“使用未定义的常量”

来自分类Dev

使用未定义的常量HOST,USER,PASS,DBSA错误?

来自分类Dev

使用未定义的常量MCRYPT_BLOWFISH

来自分类Dev

在Laravel Blade指令中使用未定义的常量

来自分类Dev

使用未定义的常量sql-假定为'sql'

来自分类Dev

在PHP中使用未定义的常量错误

来自分类Dev

即使使用正确的版本,PHP cURL常量也未定义

来自分类Dev

使用未定义的常量STDIN-假定为“ STDIN”

来自分类Dev

使用未定义的常量和mysqli_connect():

来自分类Dev

使用未定义的常量语句 - 假定的“语句”

来自分类Dev

使用未定义的常量 icontext - 假定为“icontext”

来自分类Dev

Laravel 使用未定义的常量错误 - 假设为“错误”

来自分类Dev

PHP 7.2 版未定义常量的使用

来自分类Dev

使用setTimeout时“未定义setTimeout”?

来自分类Dev

使用 MapStateToProps 时未定义 props