with('inboxes', $user->inboxes); } public function show(#[CurrentUser] User $sender, User $recipient, CreateOrGetInboxAction $action) { try { $inbox = $action->execute($recipient, $sender); } catch (\Throwable $e) { \Log::error('Inbox instantiation Failed: ', [$e->getMessage()]); abort(500); } return view('dashboards.user.chat') ->with('recipient', $recipient) ->with('inboxes', $sender->inboxes) ->with('messages', $inbox->messages()->latest()->get()); } /** * @throws \Throwable */ public function store( #[CurrentUser] User $sender, User $recipient, SendMessageRequest $request, SendMessageAction $action ) { $action->execute($sender, $recipient, $request->validated()); response()->json(['message' => 'Message sent successfully.']); } }