Edit File: FriendProfileResource.php
<?php namespace App\Http\Resources\Api\Friend; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\DB; class FriendProfileResource extends JsonResource { public function toArray($request) { return [ 'id' => $this->id, 'image' => $this->image, 'cover' => $this->cover, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'full_name' => $this->full_name, 'age' => $this->age, 'gender' => $this->gender, 'gender_text' => $this->gender_text, 'country' => $this->country?->name, 'city' => $this->city?->name, 'num_of_friends' => $this->num_of_friends, // get attr 'num_of_likes' => $this->num_of_likes, // column 'friend_status' => $this->friend_status, 'request_id' => $this->requestId() ?? null, 'bio' => $this->bio, 'is_liked' => (bool) $this->isLiked(), 'interests' => $this->groupedInterests(), ]; } public function requestId() { return DB::table('friend_requests')->where(function ($q) { $q->where('user_id', auth()->id()) ->where('friend_id', $this->id); }) ->orWhere(function ($q) { $q->where('user_id', $this->id) ->where('friend_id', auth()->id()); }) ->first()?->id; } }
Back to File Manager