I am setting up my first Laravel 4 application and the specifications require that the id fields be varchar (36) and have UUIDs.
Using Eloquent, my migrations for the sample table look like this:
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(); });
When a user table is created, the id field is not defined as PK or unique. It is defined as varchar (36) NOT NULL.
Why does this happen when the migration starts?
My initial question was about using UUIDs, but I decided that adding this to my users model if someone else sees this message:
protected $hidden = array('password'); protected $fillable = array('id', 'first_name', 'last_name', 'email', 'password');
Here is my route to add a user (I use a function to create a 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); });