From a72fe0dd2aa9564820d8659ac19775b3567c2e16 Mon Sep 17 00:00:00 2001 From: Benjamin Takats Date: Wed, 25 Jan 2023 16:54:38 +0100 Subject: [PATCH] if link --- app/Nova/Episode.php | 68 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/app/Nova/Episode.php b/app/Nova/Episode.php index ec1cdf2f..b46e0296 100644 --- a/app/Nova/Episode.php +++ b/app/Nova/Episode.php @@ -33,41 +33,43 @@ class Episode extends Resource public static function afterUpdate(NovaRequest $request, Model $model) { if ($request->tags) { - $lecturer = \App\Models\Lecturer::updateOrCreate(['name' => $model->podcast->title], [ - 'team_id' => 1, - 'active' => true, - 'website' => $model->podcast->link, - ]); - if ($model->podcast->data['image']) { - $lecturer->addMediaFromUrl($model->podcast->data['image']) - ->toMediaCollection('avatar'); - } - $library = \App\Models\Library::firstOrCreate( - [ - 'name' => 'Podcasts' + if ($model->data['link']) { + $lecturer = \App\Models\Lecturer::updateOrCreate(['name' => $model->podcast->title], [ + 'team_id' => 1, + 'active' => true, + 'website' => $model->podcast->link, ]); - $libraryItem = $model->libraryItem() - ->firstOrCreate([ - 'lecturer_id' => $lecturer->id, - 'episode_id' => $model->id, - 'name' => $model->data['title'], - 'type' => 'podcast_episode', - 'language_code' => $model->podcast->language_code, - 'value' => null, - 'excerpt' => $model->data['description'], - 'subtitle' => $model->data['description'], - ]); - $libraryItem->syncTagsWithType(is_array($request->tags) ? $request->tags : str($request->tags)->explode('-----'), - 'library_item'); - if ($model->data['image']) { - $libraryItem->addMediaFromUrl($model->data['image']) - ->toMediaCollection('main'); - } else { - $libraryItem->addMediaFromUrl($model->podcast->data['image']) - ->toMediaCollection('main'); + if ($model->podcast->data['image']) { + $lecturer->addMediaFromUrl($model->podcast->data['image']) + ->toMediaCollection('avatar'); + } + $library = \App\Models\Library::firstOrCreate( + [ + 'name' => 'Podcasts' + ]); + $libraryItem = $model->libraryItem() + ->firstOrCreate([ + 'lecturer_id' => $lecturer->id, + 'episode_id' => $model->id, + 'name' => $model->data['title'], + 'type' => 'podcast_episode', + 'language_code' => $model->podcast->language_code, + 'value' => null, + 'excerpt' => $model->data['description'], + 'subtitle' => $model->data['description'], + ]); + $libraryItem->syncTagsWithType(is_array($request->tags) ? $request->tags : str($request->tags)->explode('-----'), + 'library_item'); + if ($model->data['image']) { + $libraryItem->addMediaFromUrl($model->data['image']) + ->toMediaCollection('main'); + } else { + $libraryItem->addMediaFromUrl($model->podcast->data['image']) + ->toMediaCollection('main'); + } + $library->libraryItems() + ->attach($libraryItem); } - $library->libraryItems() - ->attach($libraryItem); } }