Created
January 30, 2018 16:21
-
-
Save pedroufv/46040ad61d482593e9ff1de9df69c0cd to your computer and use it in GitHub Desktop.
Poupula tabela de permissões
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 Illuminate\Database\Seeder; | |
class PermissionsTableSeeder extends Seeder | |
{ | |
/** | |
* Run the database seeds. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
foreach (Route::getRoutes() as $route) { | |
if ($route->getPrefix() == '/admin') { | |
$permisson = DB::table('permissions')->select('name')->where('name', '=', $route->getName())->get(); | |
if (count($permisson) == 0) { | |
$id = DB::table('permissions')->insertGetId([ | |
'name' => $route->getName(), | |
]); | |
DB::table('permission_role')->insert([ | |
'permission_id' => $id, | |
'role_id' => 1, | |
]); | |
// permite usuario editar os proprios dados | |
if($route->getName() == 'admin.profiles.edit') { | |
$permissions = new \App\Models\Permission(); | |
$permission = $permissions->find($id); | |
$permission->closure = function ($user, $id) { | |
return $user->id == $id || $user->hasRole('administrator'); | |
}; | |
$permission->save(); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment