/**
  * @param $schedule
  */
 private function _saveSchedule($schedule)
 {
     foreach ($schedule as $lineId => $lineSchedule) {
         $direction = end($lineSchedule)['stopName'];
         reset($lineSchedule);
         $publicTransport = PublicTransport::firstOrCreate(['name' => $lineId]);
         $publicTransport->setAttribute('name', $lineId);
         $publicTransport->setAttribute('direction', $direction);
         $publicTransport->save();
         foreach ($lineSchedule as $busStop) {
             $publicTransportStop = PublicTransportStop::firstOrNew(['name' => $busStop['stopName']]);
             $publicTransportStop->setAttribute('name', $busStop['stopName']);
             $publicTransportStop->save();
             foreach ($busStop['departures'] as $weekDay => $departures) {
                 foreach ($departures as $departure) {
                     $publicTransportSchedule = new PublicTransportSchedule();
                     $publicTransportSchedule->setAttribute('week_day', $weekDay);
                     $publicTransportSchedule->setAttribute('id_public_transport', $publicTransport->getAttribute('id'));
                     $publicTransportSchedule->setAttribute('id_public_transport_stop', $publicTransportStop->getAttribute('id'));
                     $publicTransportSchedule->setAttribute('departure_datetime', $departure->format('H:i:s'));
                     $publicTransportSchedule->save();
                 }
             }
         }
     }
 }
 /**
  * @param $id
  * @return array
  */
 public function getPublicTransportList($id)
 {
     $now = new \DateTime('+5 minutes');
     $schedule = DB::collection('public_transport_schedule')->orderBy('departure_datetime', 'ASC')->where('id_public_transport_stop', $id)->where('week_day', $this->_formatWeekDay($now))->where('departure_datetime', '>=', $now->format('H:i:s'))->limit(5)->get();
     $list = [];
     foreach ($schedule as $s) {
         $stop = PublicTransport::findOrNew($s['id_public_transport']);
         $list[] = ['name' => $stop['name'], 'direction' => $stop['direction'], 'time' => $s['departure_datetime']];
     }
     return $list;
 }