Prechádzať zdrojové kódy

修改 checkIN控制器 例外狀況

maa3520 2 rokov pred
rodič
commit
b2747e851f

+ 5 - 2
app/Http/Controllers/CheckInController.php

@@ -70,9 +70,12 @@ class CheckInController extends Controller
     public function show(Request $request, CheckIn $checkIn)
     {
         //
-        $checkIn = CheckIn::where('user_id', '=', $request->id)->where('activity_id', '=', $request->activity_id)->first();
+        $checkIn = $request->activity_id ?
+            CheckIn::where('user_id', '=', $request->id)->where('activity_id', '=', $request->activity_id)->first()
+            : CheckIn::where('user_id', '=', $request->id)->first();
+
         $department = Department::where('department_id', '=', $checkIn->department_id)->first();
-        $checkIn->department = $department->department_name;
+        $checkIn->department = $department->department_name ?? '暫無部門';
         $response = [
             'checkIn' => $checkIn,
         ];