/** * Salva un nuovo file caricato sul sito. * * @param MediaUploadRequest $request * @param MediaRepository $mediaRepository * @return \Illuminate\Http\RedirectResponse * @throws \LaravelItalia\Exceptions\NotSavedException */ public function postUpload(MediaUploadRequest $request, MediaRepository $mediaRepository) { $media = new Media(); $media->setUser(Auth::user()); try { $mediaRepository->save($media); } catch (NotDeletedException $e) { return redirect('admin/media')->with('error_message', 'Problemi in fase di salvataggio del media. Riprovare.'); } return redirect('admin/media')->with('success_message', 'Upload effettuato correttamente.'); }
/** * 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); }
/** * Cancella il media $media dal database. * * @param Media $media * @throws NotDeletedException * @throws \Exception */ public function delete(Media $media) { if (!$media->delete()) { throw new NotDeletedException(); } }