public static function applyDefaultUserAppRole($user, $defaultRole)
    {
        $apps = App::all();

        if (count($apps) === 0) {
            return false;
        }

        foreach ($apps as $app) {
            if (!UserAppRole::whereUserId($user->id)->whereAppId($app->id)->exists()) {
                $userAppRoleData = [
                    'user_id' => $user->id,
                    'app_id'  => $app->id,
                    'role_id' => $defaultRole
                ];

                UserAppRole::create($userAppRoleData);
            }
        }

        return true;
    }
public static function applyDefaultUserAppRole($user, $defaultRole)
    {
        $apps = App::all();

        if (count($apps) === 0) {
            return false;
        }

        foreach ($apps as $app) {
            if (!UserAppRole::whereUserId($user->id)->whereAppId($app->id)->exists()) {
                $userAppRoleData = [
                    'user_id' => $user->id,
                    'app_id'  => $app->id,
                    'role_id' => $defaultRole
                ];

                UserAppRole::create($userAppRoleData);
            }
        }

        return true;
    }
public static function applyDefaultUserAppRole ( $ user , $ defaultRole ) { $ apps = App :: all ( ) ; if ( count ( $ apps ) === 0 ) { return false ; } foreach ( $ apps as $ app ) { if ( ! UserAppRole :: whereUserId ( $ user -> id ) -> whereAppId ( $ app -> id ) -> exists ( ) ) { $ userAppRoleData = [ 'user_id' => $ user -> id , 'app_id' => $ app -> id , 'role_id' => $ defaultRole ] ; UserAppRole :: create ( $ userAppRoleData ) ; } } return true ; }
Assigns a role to a user for all apps in the system.

@param $user
@param $defaultRole

@return bool
@throws \Exception
Assigns a role to a user for all apps in the system .