Skip to content
Tom Witkowski edited this page Dec 8, 2015 · 1 revision

Seeding

Seeding roles and abilities

Depending on your project, you might have a set of roles and abilities that you want to pre-seed when you deploy your application. Bouncer ships with seeding functionality to make this as easy as possible.

First, register your seeding callback in your AppServiceProvider's boot method:

Bouncer::seeder(function () {
    Bouncer::allow('admin')->to(['ban-users', 'delete-posts']);
    Bouncer::allow('editor')->to('delete-posts');
});

You can also register a seeder class to be used for seeding:

Bouncer::seeder(MySeeder::class);

By default, the seed method will be used. If you need to, you can specify a different method:

Bouncer::seeder('MySeeder@run');

Once you've registered your seeder, you can run the seeds via the included artisan command:

$ php artisan bouncer:seed

Should you find a need to run the seeds from within your codebase, you can do that too:

Bouncer::seed();

Note that it's ok to run the seeds multiple times. If you make a change to your seeder, simply run the seeds again. However, do note that any information that has previously been seeded will not be automatically reverted.

Clone this wiki locally