diff --git a/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php b/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php new file mode 100644 index 00000000..9a18c016 --- /dev/null +++ b/Modules/Linksehat/Http/Controllers/Api/Doctor/ChatDoctorController.php @@ -0,0 +1,73 @@ + auth()->check() ? auth()->user()->id : null, + ]; + $user_id = auth()->check() ? auth()->user()->id : null; + //Get data Chat + $user = User::where('id',$user_id)->with('person')->first(); + $chat = Livechat::where([ + 'doctor_id'=> $user->person_id, + 'accept_date'=> null, + ])->get()->toArray(); + dd($chat); + + return ApiResponse::apiResponse("Success", $res_data, trans('Message.success'), 200); + + } + public function fWorkExperience($start, $end) + { + $startDateString = $start; // Tanggal dan waktu awal + $endDateString = $end ; // Tanggal dan waktu akhir + + // Mengubah string tanggal ke timestamp UNIX + $startTime = strtotime($startDateString); + $endTime = strtotime($endDateString); + + // Menghitung selisih waktu dalam detik + $timeDifference = $endTime - $startTime; + + // Menghitung jumlah tahun, bulan, dan hari dari selisih waktu + $years = floor($timeDifference / (365 * 24 * 60 * 60)); + $months = floor(($timeDifference - ($years * 365 * 24 * 60 * 60)) / (30 * 24 * 60 * 60)); + $days = floor(($timeDifference - ($years * 365 * 24 * 60 * 60) - ($months * 30 * 24 * 60 * 60)) / (24 * 60 * 60)); + + // Formatkan hasilnya + $experience = ''; + if ($years > 0) { + $experience .= $years . ' years '; + } + if ($months > 0) { + $experience .= $months . ' months '; + } + if ($days > 0) { + $experience .= $days . ' days'; + } + + return $experience; + + } +} diff --git a/Modules/Linksehat/Routes/api.php b/Modules/Linksehat/Routes/api.php index 021f4f5d..702f246b 100644 --- a/Modules/Linksehat/Routes/api.php +++ b/Modules/Linksehat/Routes/api.php @@ -20,6 +20,7 @@ use Modules\Linksehat\Http\Middleware\Doctor\Authentication; use Modules\Linksehat\Http\Middleware\Doctor\Authorization; use Modules\Linksehat\Http\Controllers\Api\Doctor\AuthDoctorController; use Modules\Linksehat\Http\Controllers\Api\Doctor\ProfileDoctorController; +use Modules\Linksehat\Http\Controllers\Api\Doctor\ChatDoctorController; /* |-------------------------------------------------------------------------- | API Routes @@ -139,6 +140,9 @@ Route::prefix('linksehat')->group(function () { Route::controller(ProfileDoctorController::class)->group(function () { Route::get('get-profile', 'getProfile'); }); + Route::controller(ChatDoctorController::class)->group(function () { + Route::get('chat', 'getChat'); + }); }); }); Route::controller(AuthDoctorController::class)->group(function () { @@ -147,6 +151,7 @@ Route::prefix('linksehat')->group(function () { Route::post('resend-code', 'forgotPassword'); Route::post('reset-password', 'resetPassword'); }); + }); }); ;}); diff --git a/routes/channels.php b/routes/channels.php index 493babbd..fbcd48df 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -1,7 +1,9 @@ id === (int) $id; -// }); - -Broadcast::channel('chat.{id}', function ($user, $id) { - return true; +Broadcast::channel('App.Models.User.{id}', function ($user, $id) { + return (int) $user->id === (int) $id; +}); + +Broadcast::channel('chat.{room_id}', function ($user, $room_id) { + return Auth::check(); });