我正在使用 Laravel 4 并尝试用一些用户为数据库播种。我正在使用Zizaco Confide插件,所以我的User
模型扩展ConfideUser
而不是Eloquent
文档。我还在模型中添加了一些字段,但没有什么超级复杂的。我试过删除这些字段,但我遇到了同样的问题。
我创建了一个UserSeeder
使用DatabaseSeeder
然后运行的类php artisan migrate:refresh --seed
。它运行没有错误并返回“数据库已播种”,对于除users
. 没有用户被插入。我已经尝试使用User::create(array(...))
as来创建用户,$user = new User ... $user->save()
并且得到了相同的结果。没有错误被转储,并且我在系统上可以找到的任何日志中都没有任何内容。如果我在 UserSeeder->run() 方法中插入一些 var_dump,我会看到这些对象是使用正确的值创建的,但没有任何保存。
我错过了什么?这是一些代码示例,如果需要,我可以提供更多:
模型\用户.php:
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use Zizaco\Confide\ConfideUser;
//class User extends Eloquent implements UserInterface, RemindableInterface {
class User extends ConfideUser
{
// for Entrust
use \Zizaco\Entrust\HasRole;
/**
* 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');
public function agency()
{
if ($this->agency_type == 'local')
{
return $this->hasOne('Local');
}
if ($this->agency_type == 'county')
{
return $this->hasOne('County');
}
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
数据库\迁移\xxxxxxxxx_confide_setup_users_table.php:
<?php
use Illuminate\Database\Migrations\Migration;
class ConfideSetupUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Creates the users table
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('username');
$table->string('email');
$table->string('password');
$table->string('confirmation_code');
$table->boolean('confirmed')->default(false);
$table->string('address1');
$table->string('address2')->nullable();
$table->string('state', 2);
$table->string('zipcode', 9);
$table->string('phone', 10);
$table->string('extension',5 )->nullable();
$table->string('fax', 10)->nullable();
$table->enum('agency_type', array('local', 'county', 'state'))->default('local');
$table->integer('agency')->unsigned()->nullable();
$table->dateTime('last_seen');
$table->timestamps();
$table->softDeletes();
});
// Creates password reminders table
Schema::create('password_reminders', function($t)
{
$t->string('email');
$t->string('token');
$t->timestamp('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('password_reminders');
Schema::drop('users');
}
}
数据库\种子\UserSeeder.php:
<?php
use \Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(
array(
'username' => 'local_test',
'email' => 'nathan@abc.com',
'password' => Hash::make('local'),
'confirmation_code' => '483JU3ID8',
'confirmed' => true,
'address1' => '123 Main St.',
'state' => 'MI',
'zipcode' => '12345',
'phone' => '5559993436',
'agency_type' => 'local',
'agency' => null,
'last_seen' => new DateTime
)
);