public static function applyAppRoleMapByService($user, $serviceId)
    {
        $maps = AppRoleMap::whereServiceId($serviceId)->get();

        foreach ($maps as $map) {
            UserAppRole::whereUserId($user->id)->whereAppId($map->app_id)->delete();
            $userAppRoleData = [
                'user_id' => $user->id,
                'app_id'  => $map->app_id,
                'role_id' => $map->role_id
            ];

            UserAppRole::create($userAppRoleData);
        }
    }
public static function applyAppRoleMapByService($user, $serviceId)
    {
        $maps = AppRoleMap::whereServiceId($serviceId)->get();

        foreach ($maps as $map) {
            UserAppRole::whereUserId($user->id)->whereAppId($map->app_id)->delete();
            $userAppRoleData = [
                'user_id' => $user->id,
                'app_id'  => $map->app_id,
                'role_id' => $map->role_id
            ];

            UserAppRole::create($userAppRoleData);
        }
    }
public static function applyAppRoleMapByService ( $ user , $ serviceId ) { $ maps = AppRoleMap :: whereServiceId ( $ serviceId ) -> get ( ) ; foreach ( $ maps as $ map ) { UserAppRole :: whereUserId ( $ user -> id ) -> whereAppId ( $ map -> app_id ) -> delete ( ) ; $ userAppRoleData = [ 'user_id' => $ user -> id , 'app_id' => $ map -> app_id , 'role_id' => $ map -> role_id ] ; UserAppRole :: create ( $ userAppRoleData ) ; } }
Applies App to Role mapping to a user.

@param User    $user
@param integer $serviceId
Applies App to Role mapping to a user .