/** * Import flyer from url. * * @param string $url * @param bool $replace * @return bool */ public function importFlyer($url = null, $replace = false) { $existingFlyer = null; if ($replace) { $existingFlyer = $this->flyers->first(); // @TODO: Backwards compatibility, remove when Anqh is killed if (!$existingFlyer && $this->flyer_id) { $existingFlyer = FlyerModel::find($this->flyer_id); } } if ($url && $url != $this->flyer_url) { // Import flyer from new url $flyerUrl = $url; } else { if (!$url && $this->flyer_url) { // Import flyer from existing url $flyerUrl = $this->flyer_url; } } if (isset($flyerUrl)) { return Db::transaction(function () use($flyerUrl, $existingFlyer) { $flyer = FlyerModel::importToEvent($this, $flyerUrl, $existingFlyer); $this->flyer_url = $flyerUrl; $this->flyer_front_url = url($flyer->image->getPath()); return $this->save(); }); } return false; }