/** * @param array $data * @return Exhibition */ public function createAndSave(array $data) { $exhibition = isset($data['id']) ? Exhibition::find($data['id']) : new Exhibition(); if (isset($data['exhibition_film']['id'])) { $exhibitionFilm = ExhibitionFilm::find($data['exhibition_film']['id']); } else { $exhibitionFilm = new ExhibitionFilm(); } $exhibitionFilm->film_id = $data['exhibition_film']['film']['id']; $exhibitionFilm->save(); $exhibition->exhibitionFilm()->associate($exhibitionFilm); $exhibition->notes = isset($data['notes']) ? $data['notes'] : ''; if (isset($data['icon']['id'])) { $exhibition->type_id = $data['icon']['id']; } else { $exhibition->type_id = null; } $exhibition->save(); Schedule::where('exhibition_id', $exhibition->id)->delete(); $schedules = array_reduce($data['schedules'], function ($schedules, $rawSchedule) { $schedule = new Schedule(); $schedule->entry = $rawSchedule['entry']; $schedule->auditorium_id = $rawSchedule['auditorium']['id']; $schedules[] = $schedule; return $schedules; }, []); $exhibition->schedules()->saveMany($schedules); return Exhibition::findOrFail($exhibition->id); }
public function update($id, array $data = null) { $exhibition = $this->resource->findOrFail($data['id'])->fill($data); $exhibition->save(); return true; }