protected function syncRoles(array $roles)
    {
        /** @var \Illuminate\Database\Eloquent\Collection $permissions */
        $permissions = Permission::all();

        foreach ($roles as $roleSlug => $permissionSlug) {
            /** @var  \Arcanesoft\Auth\Models\Role  $role */
            if ($role = Role::query()->where('slug', $roleSlug)->first()) {
                $filtered = $permissions->filter(function (Permission $permission) use ($permissionSlug) {
                    return Str::startsWith($permission->slug, $permissionSlug);
                });

                $role->permissions()->sync(
                    $filtered->pluck('id')->toArray()
                );
            }
        }
    }
protected function syncRoles(array $roles)
    {
        /** @var \Illuminate\Database\Eloquent\Collection $permissions */
        $permissions = Permission::all();

        foreach ($roles as $roleSlug => $permissionSlug) {
            /** @var  \Arcanesoft\Auth\Models\Role  $role */
            if ($role = Role::query()->where('slug', $roleSlug)->first()) {
                $filtered = $permissions->filter(function (Permission $permission) use ($permissionSlug) {
                    return Str::startsWith($permission->slug, $permissionSlug);
                });

                $role->permissions()->sync(
                    $filtered->pluck('id')->toArray()
                );
            }
        }
    }
protected function syncRoles ( array $ roles ) { /** @var \Illuminate\Database\Eloquent\Collection $permissions */ $ permissions = Permission :: all ( ) ; foreach ( $ roles as $ roleSlug => $ permissionSlug ) { /** @var  \Arcanesoft\Auth\Models\Role  $role */ if ( $ role = Role :: query ( ) -> where ( 'slug' , $ roleSlug ) -> first ( ) ) { $ filtered = $ permissions -> filter ( function ( Permission $ permission ) use ( $ permissionSlug ) { return Str :: startsWith ( $ permission -> slug , $ permissionSlug ) ; } ) ; $ role -> permissions ( ) -> sync ( $ filtered -> pluck ( 'id' ) -> toArray ( ) ) ; } } }
Sync the roles.

@param  array  $roles
Sync the roles .