belongsTo(Nation::class); } public function province() { return $this->belongsTo(Province::class); } public function city() { return $this->belongsTo(City::class); } public function birth_nation() { return $this->belongsTo(Nation::class); } public function birth_province() { return $this->belongsTo(Province::class); } public function birth_city() { return $this->belongsTo(City::class); } public function isActive() { $ret = array('status' => false, 'date' => ''); $cards = \App\Models\MemberCard::where('member_id', $this->id)->with('card')->orderBy('expire_date')->get(); foreach($cards as $card) { if ($card->card->use_for_user_check) { $ret = array('status' => $card->expire_date > date("Y-m-d"), 'date' => $card->expire_date); } } return $ret; } public function getMoney() { $ret = 0; // Soldi virtuali caricati $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->with('causal')->get(); foreach($records as $record) { if ($record->causal->money == 1) { $ret += $record->amount; } } // Soldi virtuali spesi $records = \App\Models\Record::where('member_id', $this->id)->where('type', 'IN')->with('payment_method')->get(); foreach($records as $record) { if ($record->payment_method->money == 1) { $ret -= $record->amount; } } return $ret; } }