feat: 即時預約聊天室(realtime booking chat)
## 新增功能 - 會員與教練在 confirmed 預約期間可互傳文字與圖片訊息 - Presence Channel 顯示對方在線狀態(即時加入/離線) - 已讀回執:對方讀取訊息後即時更新 - 預約完成(completed)後訊息封存唯讀 - 圖片上傳使用 intervention/image 處理(移除 EXIF、限制尺寸、強制重新編碼) ## 通知系統 - 收到新訊息時 Bell Icon 即時更新(NotificationCreated via private channel) - 預約列表卡片顯示未讀角標(GET /api/bookings/messages/unread-counts 批次查詢) - 瀏覽器分頁在背景時推送 Web Notification ## 基礎建設 - 引入 Laravel Reverb 作為自架 WebSocket 伺服器 - docker-compose 新增 reverb service(連接 proxy_net,供 NPM 代理) - 前端安裝 laravel-echo + pusher-js,初始化 Echo plugin - Dockerfile 補 GD JPEG/WebP/FreeType 支援 ## 清理 - 移除 test_broadcast.php 與 resources/js/echo.js(Blade 殘留) - 移除 /ping、/testpost 測試路由 - channels.php 改用 class-based 授權語法,移除 debug log - BookingChat.vue otherType 提取為 computed 消除重複 - docker-entrypoint.sh 健康檢查改用 env var 取代硬編碼密碼 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+12
-12
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\API\AuthController;
|
||||
use App\Http\Controllers\API\DivingOfferController;
|
||||
@@ -14,12 +15,10 @@ use App\Http\Controllers\API\CourseImageController;
|
||||
use App\Http\Controllers\API\AdminStatsController;
|
||||
use App\Http\Controllers\API\AdminUserController;
|
||||
use App\Http\Controllers\API\AdminOfferController;
|
||||
use App\Http\Controllers\API\BookingMessageController;
|
||||
use App\Http\Controllers\API\NotificationController;
|
||||
|
||||
// 這裡可以定義 API 路由,例如:
|
||||
Route::get('/ping', function () {
|
||||
return response()->json(['message' => 'pong']);
|
||||
});
|
||||
Broadcast::routes(['middleware' => ['auth:sanctum']]);
|
||||
|
||||
// 潛水課程(公開)
|
||||
Route::get('/diving-offers', [DivingOfferController::class, 'index']);
|
||||
@@ -27,14 +26,6 @@ Route::get('/diving-offers/{id}', [DivingOfferController::class, 'show']);
|
||||
Route::get('/diving-offers/{id}/schedules', [ScheduleController::class, 'publicList']);
|
||||
Route::get('/diving-offers/{id}/reviews', [ReviewController::class, 'publicList']);
|
||||
|
||||
// 你可以在這裡繼續新增 API 路由
|
||||
Route::post('/testpost', function () {
|
||||
$data = request()->all(); // 取得所有POST資料(array)
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
]);
|
||||
});
|
||||
|
||||
// 會員註冊/登入
|
||||
Route::post('/member/register', [AuthController::class, 'registerMember']);
|
||||
Route::post('/member/login', [AuthController::class, 'loginMember']);
|
||||
@@ -153,6 +144,15 @@ Route::middleware('auth:sanctum')->prefix('notifications')->group(function () {
|
||||
Route::delete('/{id}', [NotificationController::class, 'destroy']);
|
||||
});
|
||||
|
||||
// 即時訊息(Member + Provider 共用,依 booking 參與方驗證)
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
// unread-counts 必須在 {booking} 之前,否則會被 route model binding 吃掉
|
||||
Route::get('/bookings/messages/unread-counts', [BookingMessageController::class, 'unreadCounts']);
|
||||
Route::get('/bookings/{booking}/messages', [BookingMessageController::class, 'index']);
|
||||
Route::post('/bookings/{booking}/messages', [BookingMessageController::class, 'store']);
|
||||
Route::post('/bookings/{booking}/messages/read', [BookingMessageController::class, 'markRead']);
|
||||
});
|
||||
|
||||
// 需要認證的通用路由
|
||||
Route::middleware('auth:sanctum')->group(function () {
|
||||
Route::post('/logout', [AuthController::class, 'logout']);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use App\Broadcasting\BookingPresenceChannel;
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
|
||||
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
||||
return (int) $user->id === (int) $id;
|
||||
});
|
||||
|
||||
Broadcast::channel('booking.{booking}', BookingPresenceChannel::class);
|
||||
Reference in New Issue
Block a user