'datetime', 'last_on' => 'datetime:Y-m-d H:i:s', 'passkey' => 'json', ]; /* RELATIONS */ public function system() { return $this->belongsTo(System::class); } public function systems() { return $this->belongsToMany(System::class); } /* GENERAL METHODS */ public function addresses(Domain $o=NULL): Collection { return Address::select('addresses.*') ->join('systems',['systems.id'=>'addresses.system_id']) ->join('system_user',['system_user.system_id'=>'systems.id']) ->when(! is_null($o),function($query) use ($o) { return $query ->join('zones',['zones.id'=>'addresses.zone_id']) ->where('zones.domain_id',$o->id); }) ->where('system_user.user_id',$this->id) ->activeFTN() ->with(['zone.domain']) ->get(); } /** * Is this user a ZC of a domain? * * @return bool */ public function isZC(): bool { return $this->zc()->count() > 0; } /** * Does this user have systems with points * * @return Collection */ public function points(): Collection { return $this ->systems ->pluck('addresses') ->flatten() ->where('point_id','>',0); } /** * Return the zones that this user is ZC for * * @return Collection */ public function zc(): Collection { $this->load('systems.addresses.nodes_hub'); return $this->systems->pluck('addresses')->flatten()->where('role_id',Address::NODE_ZC); } }