Created
December 16, 2017 18:42
-
-
Save ashokgelal/e6e8f17adb913151a0339aa9a21a1f8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\Permission; | |
use Illuminate\Database\Seeder; | |
use Spatie\Permission\Models\Role; | |
class TenantDatabaseSeeder extends Seeder | |
{ | |
public function run() | |
{ | |
$this->addRolesAndPermissions(); | |
} | |
private function addRolesAndPermissions() | |
{ | |
// create permissions for an admin | |
$adminPermissions = collect(['create user', 'edit user', 'delete user'])->map(function ($name) { | |
return Permission::create(['name' => $name]); | |
}); | |
// add admin role | |
$adminRole = Role::create(['name' => 'admin']); | |
$adminRole->givePermissionTo($adminPermissions); | |
// add a default user role | |
Role::create(['name' => 'user']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment