trs_matrimony/app/Http/Resources/ChatResource.php
2024-08-22 09:31:12 +05:30

31 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Http\Resources\Chat\ChatViewResource;
use Illuminate\Http\Resources\Json\JsonResource;
class ChatResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$chats = $this->chats()->latest()->get();
$user_to_show = auth()->id() !== $this->sender->id ? 'receiver' : 'sender';
return [
'receiver_name' => $this->receiver->first_name . ' ' . $this->receiver->last_name,
'receiver_photo' => $this->receiver->photo != null ? uploaded_asset($this->receiver->photo) : static_asset('assets/frontend/default/img/avatar-place.png'),
'sender_name' => $this->sender->first_name . ' ' . $this->sender->last_name,
'auth_user_photo' => uploaded_asset(auth()->user()->photo) !== null ? uploaded_asset(auth()->user()->photo) : static_asset('assets/frontend/default/img/avatar-place.png'),
'messages' => ChatViewResource::collection($chats),
// 'sender_messages'=>$this->sender->$chats,
// 'receiver_messages'=>$this->receiver->$chats,
];
}
}