Skip to content

Instantly share code, notes, and snippets.

@marcellorg
Created March 17, 2018 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcellorg/bbf553d8ad12d16d01f1a573a071d9fd to your computer and use it in GitHub Desktop.
Save marcellorg/bbf553d8ad12d16d01f1a573a071d9fd to your computer and use it in GitHub Desktop.
<?php
use Silber\Bouncer\Database\Models;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use CircleSystem\Models\User;
class PermissionTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
$this->cleanTable();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
Model::reguard();
$this->superAdmin();
$this->partners();
$this->supervisors();
}
private function cleanTable()
{
DB::table(Models::table('acl_abilities'))->truncate();
DB::table(Models::table('permissions'))->truncate();
DB::table(Models::table('acl_roles'))->truncate();
DB::table(Models::table('acl_assigned_roles'))->truncate();
}
private function superAdmin()
{
$user = config('settings.acl.users.superadmin');
if(!is_array($user)){
$user = explode(',', config('settings.acl.users.supervisors'));
}
$users = User::find($user);
$this->command->info("Super Admins:");
foreach ($users as $user) {
Bouncer::allow($user)->everything();
$this->command->info($user->name." (".$user->id.") - ".$user->email);
}
}
private function partners()
{
Bouncer::allow('partners')->to([
'account-validate',
'user-dashboard-financial',
'user-dashboard-financial-company'
]);
$user = config('settings.acl.users.partners');
if(!is_array($user)){
$user = explode(',', config('settings.acl.users.supervisors'));
}
$users = User::find($user);
$this->command->info("Sócios:");
foreach ($users as $user) {
Bouncer::assign('partners')->to($user);
$this->command->info($user->name." (".$user->id.") - ".$user->email);
}
}
private function supervisors()
{
Bouncer::allow('supervisors')->to([
'account-validate'
]);
$user = config('settings.acl.users.supervisors');
if(!is_array($user)){
$user = explode(',', config('settings.acl.users.supervisors'));
}
$users = User::find($user);
$this->command->info("Supervisores:");
foreach ($users as $user) {
Bouncer::assign('supervisors')->to($user);
$this->command->info($user->name." (".$user->id.") - ".$user->email);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment