where('id', $tripId) ->where('created_by_user_id', $user->id) ->exists(); } /** * Determine if the user can update the planned item */ public function update(User $user, PlannedItem $plannedItem): bool { return \DB::table('planned_items') ->join('calendar_slots', 'planned_items.calendar_slot_id', '=', 'calendar_slots.id') ->join('trips', 'calendar_slots.trip_id', '=', 'trips.id') ->where('planned_items.id', $plannedItem->id) ->where('trips.created_by_user_id', $user->id) ->exists(); } /** * Determine if the user can delete the planned item */ public function delete(User $user, PlannedItem $plannedItem): bool { return $this->update($user, $plannedItem); } /** * Determine if the user can move a planned item to a new calendar slot */ public function moveToSlot(User $user, int $calendarSlotId): bool { return \DB::table('calendar_slots') ->join('trips', 'calendar_slots.trip_id', '=', 'trips.id') ->where('calendar_slots.id', $calendarSlotId) ->where('trips.created_by_user_id', $user->id) ->exists(); } }