belongsTo(Participant::class, 'giving_id'); } public function giver(): hasOne { return $this->hasOne(Participant::class, 'giving_id', 'id'); } public static function findByToken(string $token): ?self { return self::where('token', $token)->first(); } public function getUserData(): ?array { if (!$this->token) return null; $url = "https://sketchersunited.org/users/{$this->user_id}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json' ]); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($response !== false && $httpCode === 200) { return json_decode($response, true); } Log::info($this->user_id); return null; } public static function withoutReceivers() { return self::whereNotNull('giving_id') ->whereDoesntHave('receiver'); } public function getDesperateAttribute(): bool { $gives = !is_null($this->giver); $gets = !is_null($this->receiver); return ($gives && !$gets) || (!$gives && $gets); } public function withdraw(): bool { return false; } }