public function deleting(Series $series)
 {
     $articles = $series->articles()->get();
     foreach ($articles as $article) {
         $article->delete();
     }
 }
 /**
  * Register any other events for your application.
  *
  * @param \Illuminate\Contracts\Events\Dispatcher $events
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     Article::observe(DetachCategoriesBeforeArticleDelete::class);
     Media::observe(UploadFileWhenAddingMedia::class);
     Media::observe(RemoveFileWhenDeletingMedia::class);
     Series::observe(RemoveArticlesWhenDeletingSeries::class);
     Category::observe(DetachArticlesWhenDeletingCategory::class);
 }
 /**
  * Salva una nuova serie i cui dati sono passati in $request.
  *
  * @param SeriesSaveRequest $request
  * @param SeriesRepository $seriesRepository
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postAdd(SeriesSaveRequest $request, SeriesRepository $seriesRepository)
 {
     $series = Series::createFromTitleAndDescriptionAndMetaDescription($request->get('title'), $request->get('description'), $request->get('metadescription'));
     try {
         $seriesRepository->save($series);
     } catch (NotSavedException $e) {
         return redirect('admin/series/add')->withInput()->with('error_message', 'Problemi in fase di salvataggio. Riprovare.');
     }
     return redirect('admin/series')->with('success_message', 'La serie è stata aggiunta correttamente.');
 }
 private function findOrCreateSeriesFor($article)
 {
     // yes, I used the shitty name "serie" to play with the Eloquent singular/plural
     if (intval($article['serie_id']) === 0) {
         return null;
     }
     /* @var SeriesRepository $seriesRepository */
     $seriesRepository = app(SeriesRepository::class);
     try {
         $series = $seriesRepository->findBySlug($article['serie']['slug']);
     } catch (NotFoundException $e) {
         $series = Series::createFromTitleAndDescriptionAndMetaDescription($article['serie']['title'], $article['serie']['description'], $article['serie']['metadescription']);
         $series->is_published = boolval($article['serie']['is_visible']);
         $series->is_completed = boolval($article['serie']['is_finished']);
         $seriesRepository->save($series);
     }
     return $series;
 }
 /**
  * Restituisce un articolo a partire dal suo slug e dalla sua appartenenza alla serie $series. Se $onlyPublished è
  * true, solo se mandato in pubblicazione. Se $onlyVisible è true, solo se già pubblicato e visibile.
  *
  * @param Series $series
  * @param $slug
  * @param bool $onlyPublished
  * @param bool $onlyVisible
  * @return mixed
  * @throws NotFoundException
  */
 public function findBySeriesAndSlug(Series $series, $slug, $onlyPublished = false, $onlyVisible = false)
 {
     $query = $series->articles()->with(['user', 'categories', 'series']);
     if ($onlyPublished) {
         $query->published();
     }
     if ($onlyVisible) {
         $query->visible();
     }
     $result = $query->where('slug', '=', $slug)->first();
     if (!$result) {
         throw new NotFoundException();
     }
     return $result;
 }
 public function saveTestSeries($title)
 {
     $series = new Series();
     $series->title = $title;
     $series->slug = \Illuminate\Support\Str::slug($title);
     $series->is_published = true;
     $series->is_completed = true;
     $series->save();
     return $series;
 }
 /**
  * Rimuove dal database la serie $series passata.
  *
  * @param Series $series
  * @throws \Exception
  */
 public function delete(Series $series)
 {
     $series->delete();
 }