Sunday 15 May 2011

php - Laravel 4 using UUID as primary key -


I am installing my first Laravel 4 app and the ID field to be varchar (36), specs call and a UIID .

Using a legend, my migration looks like this for a sample table: schema :: create ('user', function ($ table) {$ Table- & gt; string ('id', 36) - & gt; primary; $ table- & gt; string ('first_name', 50); $ table- & gt; string ('last_name', 50); $ Table- & gt; string 'email') - & gt; Unique (); $ Table- & gt; String ('password', 60); $ Table- & gt; Timestamp (); $ Table- & gt; Softdelts ();});

When a user's table is created, the id field is not defined as PK, or exclusive. It is defined as varchar (36) naul.

Why is this happening while running this migration?


My basic question was about using UUID, but I understand that adding this to your user model, someone else should see this post:

  Protected $ hidden = array ('password'); $ Fillable = array ('id', 'first_name', 'last_name', 'email', 'password' secure);   

There is my way to add a user (I'm using a function to create a UUID):

  Route: Post ( 'Signup' function () {$ userdata = array ('id' => gt; yes_uuid (), 'first_name' = & gt; Input :: find ('first_name'), 'last_name' => input :: Get ('last_name'), 'email' = & gt; input :: find ('email'), 'password' = & gt; hash :: create (input :: ('password')); $ User = new user ($ userdata); $ User- & gt; Save (); Return View: create ('login / login') -> with ('userdata', $ userdata);});    

this line

  $ table-> ; String ('id', 36) - & gt; Primary;   

  $ table-> String ('id', 36) - & gt; Should be converted to primary ();    

No comments:

Post a Comment