6
我正在设置我的第一个Laravel 4应用程序,并且规范要求将id字段设置为varchar(36)并且是UUID。使用UUID作为主键的Laravel 4
使用侃侃而谈,我迁移了一个示例表看起来是这样的:
Schema::create('users', function($table)
{
$table->string('id', 36)->primary;
$table->string('first_name', 50);
$table->string('last_name', 50);
$table->string('email')->unique();
$table->string('password', 60);
$table->timestamps();
$table->softDeletes();
});
当用户表被创建,id字段没有被定义为PK,或独特的。它被定义为varchar(36)NOT NULL。
为什么在我运行迁移时发生这种情况?
我原来的问题是关于使用UUID,但我感觉解决,通过增加这万一别人我的用户模型,看到这个帖子:
protected $hidden = array('password');
protected $fillable = array('id', 'first_name', 'last_name', 'email', 'password');
这里是我的添加路由用户(我用一个函数来创建UUID):
Route::post('signup', function()
{
$userdata = array(
'id' => gen_uuid(),
'first_name' => Input::get('first_name'),
'last_name' => Input::get('last_name'),
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'))
);
$user = new User($userdata);
$user->save();
return View::make('login/login')->with('userdata', $userdata);
});
- >伯或 - >初级()? –
是的!做出答案。 – Jazzy
你用什么函数来生成UUID?它是定制还是内置于Laravel? – Mike