logFlightActions('flight_departing', UserFlight::where('departure_date', $time)->get()->toArray()); $this->logFlightActions('flight_arriving', UserFlight::where('arrival_date', $time)->get()->toArray()); } /** * @param string $type * @param UserFlight[] $flights * @return void */ private function logFlightActions(string $type, array $flights): void { foreach ($flights as $flight) { UserAction::create([ 'user_id' => $flight->user_id, 'type' => $type, 'data' => $flight->snapshot($flight->id), ]); } } }