src/Console/Commands/PermissionsSync.php
public function handle()
    {
        if (count($this->routes) == 0) {
            return $this->error("Application doesn't have any routes.");
        }

        $routes = $this->getRoutes();
        $global = \Unite\UnisysApi\Models\Permission::getGlobalPermissions();

        $permissions = $routes->merge($global);

        Permission::all()->each(function (Permission $permission) use($permissions) {
            if(!$permissions->contains($permission->name)) {
                $permission->delete();
            }
        });

        $permissions->each(function ($name) {
            try {
                Permission::findByName($name);
            } catch (PermissionDoesNotExist $e) {
                Permission::create(['name' => $name]);
            }
        });

        $this->info('Permissions was synced');
    }
public function handle()
    {
        if (count($this->routes) == 0) {
            return $this->error("Application doesn't have any routes.");
        }

        $routes = $this->getRoutes();
        $global = \Unite\UnisysApi\Models\Permission::getGlobalPermissions();

        $permissions = $routes->merge($global);

        Permission::all()->each(function (Permission $permission) use($permissions) {
            if(!$permissions->contains($permission->name)) {
                $permission->delete();
            }
        });

        $permissions->each(function ($name) {
            try {
                Permission::findByName($name);
            } catch (PermissionDoesNotExist $e) {
                Permission::create(['name' => $name]);
            }
        });

        $this->info('Permissions was synced');
    }
/*
Execute the console command.