昨晚我在 Laravel 开始了一个项目,我正在使用 Ardent 和 Entrust 包来帮助使我的用户模型更加安全和易于使用。我已经设置了所有内容,但无法为我的数据库播种。没有抛出错误,但它绝对没有保存到我的数据库中。
这是我的用户模型。
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use LaravelBook\Ardent\Ardent;
use Zizaco\Entrust\HasRole;
class User extends Ardent implements UserInterface, RemindableInterface {
use HasRole;
public static $rules = array(
'username' => 'required|alpha_num|between:6,18|unique:users',
'email' => 'required|email|unique:users',
'password' => 'required|alpha_num|min:8',
'password_confirmation' => 'required|alpha_num|min:8',
'first_name' => 'alpha',
'last_name' => 'alpha',
'city' => 'alpha',
'state' => 'alpha',
'rate' => 'numeric',
'profile_pic' => 'image',
'commitment' => 'string'
);
public static $passwordAttributes = array('password');
public $autoHydrateEntityFromInput = true;
public $forceEntityHydrationFromInput = true;
public $autoPurgeRedundantAttributes = true;
public $autoHashPasswordAttributes = true;
protected $table = 'users';
protected $hidden = array('password');
public function getAuthIdentifier()
{
return $this->getKey();
}
public function getAuthPassword()
{
return $this->password;
}
public function getReminderEmail()
{
return $this->email;
}
}
这是users
我迁移中的模式。
Schema::create(
'users',
function (Blueprint $table) {
$table->increments('id');
$table->string('username');
$table->string('email');
$table->string('password', 60);
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('city')->nullable();
$table->string('state', 2)->nullable();
$table->string('zip', 9)->nullable();
$table->float('rate', 10, 2)->nullable();
$table->boolean('listed')->default(false);
$table->string('profile_pic')->nullable();
$table->string('commitment')->nullable();
$table->timestamps();
$table->softDeletes();
}
);
最后,这是我的种子数据。
$admin = User::create(
array(
'username' => 'admin',
'email' => 'admin@example.com',
'password' => 'admin',
'password_confirmation' => 'admin',
'first_name' => 'Admin',
'last_name' => 'User',
'city' => 'Cincinnati',
'state' => 'OH',
'zip' => '45243'
)
);
User::create(
array(
'username' => 'user',
'email' => 'user@example.com',
'password' => 'user',
'password_confirmation' => 'user',
'first_name' => 'Normal',
'last_name' => 'User'
)
);
我已将范围缩小到在我的用户模型中扩展 Ardent 的事实,但我不知道为什么。