I have a database table for "roles" and for "permissions", and I need to seed these with the correct roles/permissions initially, but in the future I'm expecting to add new roles, and new permissions to the database.
Step 1 I've created the migration files, and migrated the database tables for "roles" and "permissions"
Step 2 I've created a seeder file for each table, and added the current roles/permissions to populate the DB.
Now I'm wondering what I do when I come to add another role or permission? Do I create another database seeder, or do I modify the other one? If i modify the other one then surely it will re-add the same content again. If I clear the table then re-seed it, the auto increment ID's will be wrong.
Probably haven't done the best job of explaining this, but the best I can come up with is to Seed the database with Migrations, as I can then ensure the right data is added at the right time. But this doesn't seem like a very good solution.
Also, if you haven't yet noticed. I'm a bit of a beginner with anything more advanced than WordPress, so go easy :) Thanks in advance
You can use
php artisan migrate:refresh --seed
It combines
php artisan migrate:reset
php artisan migrate
php artisan db:seed
Make sure that your down functions in your migrations is correct since it resets the database.
This will remove all the data in all your tables so don't use this if the data isn't only created from your seeds.
I'm just starting a new web app and have encountered the same issue.
Would it be best practice to not use auto incrementing ID's on tables that contain base data for an application? As in chrisgeary92's issue above: if the roles/permissions table didn't use incrementing ID's then you could just re-seed that table with new data and your ID's would remain the same.
You could still use auto-increments on the table even if you specify the ID explicitly when you insert. For example:
DB::table('foo')->insert(
array('id' => 1, 'bar' => 'baz'),
array('id' => 3, 'bar' => $whateverFillerWordComesAfterBaz)
);
Now if you insert another row without specifying an ID, the autoincrement should set it to 4.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community