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 ) { try { $action->execute($sender, $recipient, $request->validated()); return response()->json(['message' => 'Message sent successfully.']); } catch (MessageNotSendException $e) { Log::error('Message send failed', [$e->getMessage()]); return response()->json(['message' => 'Message sent failed.'], 500); } } }