| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Http\Controllers;
- use App\Jobs\SetChatTitleJob;
- use App\Models\Chat;
- use App\Services\MessageService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Bus;
- class ChatController extends Controller
- {
- /**
- * @throws \Throwable
- */
- public function store(MessageService $service, Request $request)
- {
- $chat = $request->user()->chats()->create();
- $service->create($chat, $request->string('message'));
- $batch = Bus::batch([new SetChatTitleJob($chat)])
- ->name('Generate Chat Title')
- ->onQueue('secondary')
- ->dispatch();
- $chat->batches()->attach($batch->id);
- return redirect()->route('chats.show', $chat->id);
- }
- public function create()
- {
- return inertia('Chat/Create');
- }
- public function show(Chat $chat)
- {
- $chat->load('messages');
- return inertia('Chat/View', [
- 'chat' => fn() => $chat->toResource(),
- ]);
- }
- public function destroy(Chat $chat)
- {
- $chat->delete();
- return redirect()->route('chats.index');
- }
- }
|