'desc']; public static function afterUpdate(NovaRequest $request, Model $model) { if ($request->tags) { if ($model->data['link']) { $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', ]); $libraryItem = $model->libraryItem() ->firstOrCreate([ 'lecturer_id' => $lecturer->id, 'episode_id' => $model->id, 'name' => $model->data['title'], 'type' => 'podcast_episode', 'language_code' => str($model->podcast->language_code) ->before('-') ->toString(), '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); } } } public static function afterCreate(NovaRequest $request, Model $model) { \App\Models\User::find(1) ->notify(new ModelCreatedNotification($model, str($request->getRequestUri()) ->after('/nova-api/') ->before('?') ->toString())); } protected static function applyOrderings($query, array $orderings) { if (empty($orderings) && property_exists(static::class, 'orderBy')) { $orderings = static::$orderBy; } return parent::applyOrderings($query, $orderings); } public function title() { return $this->data['title']; } public function subtitle() { return __('Created by: :name', ['name' => $this->createdBy->name]); } /** * Get the fields displayed by the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function fields(Request $request): array { return [ ID::make() ->sortable(), Avatar::make(__('Image')) ->squared() ->thumbnail(function () { return $this->data['image']; }) ->exceptOnForms(), Tags::make(__('Tags')) ->type('library_item') ->withLinkToTagResource(Tag::class), Text::make(__('Title'), 'data->title') ->readonly() ->rules('required', 'string'), Code::make(__('Data'), 'data') ->readonly() ->rules('required', 'json') ->json(), BelongsTo::make(__('Podcast'), 'podcast', Podcast::class) ->readonly(), BelongsTo::make(__('Created By'), 'createdBy', User::class) ->canSee(function ($request) { return $request->user() ->hasRole('super-admin'); }) ->searchable(), ]; } /** * Get the cards available for the request. * * @param \Illuminate\Http\Request $request * @return array */ public function cards(Request $request): array { return []; } /** * Get the filters available for the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function filters(Request $request): array { return []; } /** * Get the lenses available for the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function lenses(Request $request): array { return []; } /** * Get the actions available for the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function actions(Request $request): array { return []; } }