Skip to content

Instantly share code, notes, and snippets.

@pedroufv
Created January 30, 2018 16:21
Show Gist options
  • Save pedroufv/46040ad61d482593e9ff1de9df69c0cd to your computer and use it in GitHub Desktop.
Save pedroufv/46040ad61d482593e9ff1de9df69c0cd to your computer and use it in GitHub Desktop.
Poupula tabela de permissões
<?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