4

Im trying to add fields to the Users model that is based around Sentry 2 for Laravel 4.

I want to do it properly with migrations.

Is there a way to simply add to the sentry 2 migrations? or should i simply make my own migrations and add the required extra fields?

any guidance with the framework would be awesome!

andrewsi
  • 10,807
  • 132
  • 35
  • 51
AndrewMcLagan
  • 13,459
  • 23
  • 91
  • 158

3 Answers3

11

If you want add some fields you need this:

  • run Sentry Migrations: php artisan migrate --package=cartalyst/sentry
  • create a migration to add custom fields to Users table: php artisan migrate:make --table=users
  • example in funcion up():

Schema::table('users', function(Blueprint $table) { $table->string('new_field'); });

  • And then extend the Sentry User Model:

Check this example is extending Sentry Model and full implementation example check this: Laravel 4 Backend and simple web site

Bradley
  • 455
  • 5
  • 11
  • 3
    Worked perfectly but only one small mistake, you need to add table name "php artisan migrate:make users --table=users" rest of is pefect – Iori Dec 22 '13 at 06:48
3

The best way to do this is simple navigate to the actual sentry migration file found at

vendor/cartalyst/sentry/src/migrations

copy the needed migrations out and create your own migrations file.

There is no other way. Just me being lazy i guess.

AndrewMcLagan
  • 13,459
  • 23
  • 91
  • 158
3

The purpose of migrations is versioning of the database structure. The answer to any question similar to "where should I put database changes?" is always: "in a new migration", because then you're able to rollback changes.

In this case, I think I would first add Sentry 2 to your project and commit "Added Sentry 2". After, I would create a new migration with your desired changes, then commit: "Added fields x y and z to Users table".

See also the introduction paragraph of the documentation: http://four.laravel.com/docs/migrations

Dirk
  • 2,167
  • 2
  • 20
  • 29