user->parent_id != null){ $upline = User::find($this->user->parent_id); if($upline){ $upline = $upline->name; } } $published_videos = StudioPlusVideo::whereHas('channel', function($query){ $query->where('user_id', $this->user->id); })->where('status',StudioPlusVideo::STATUS_PUBLISHED)->count(); return [ 'id' => $this->id, 'user_id' => $this->user->id, 'first_name' => $this->user->first_name, 'last_name' => $this->user->last_name, 'name' => $this->user->name, 'username' => $this->user->username, 'date_of_birth' => $this->user->date_of_birth, 'email' => $this->user->email, 'phone' => $this->user->phone, 'avatar' => $this->user->avatar != null ? url("/public/{$this->user->avatar}") : null, 'ott_photo' => $this->ott_photo != null ? url("/public/{$this->ott_photo}") : null, 'upline' => $upline, 'role_id' => $this->user->role->id, 'role' => $this->user->role->name, 'badges' => $this->badges, 'department_id' => $this->department->id, 'department' => $this->department->name, 'parent_id' => $this->user->parent_id, 'is_active' => (boolean)$this->user->is_active, 'published_videos' => $published_videos, 'created_at' => $this->created_at->format('Y-m-d'), 'updated_at' => $this->updated_at, ]; } }