6

私は最初の Laravel 4 アプリをセットアップしています。仕様では、id フィールドが varchar(36) であり、UUID である必要があります。

Eloquent を使用すると、サンプル テーブルの移行は次のようになります。

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();
});

users テーブルが作成されると、id フィールドは PK または一意として定義されません。varchar(36) NOT NULL として定義されます。

移行を実行すると、なぜこのようなことが起こるのですか?


私の最初の質問はUUIDの使用に関するものでしたが、他の誰かがこの投稿を見た場合に備えて、これをUsersモデルに追加することで解決しました:

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);
}); 
4

1 に答える 1