title)){ return $this->id; } return $this->title; } /** * The columns that should be searched. * * @var array */ public static $search = [ 'id', 'title', 'body' ]; public static function indexQuery(NovaRequest $request, $query) { return $query->where('status', '!=', 1)->where('is_ads', false)->with('user.subscription'); } /** * Get the fields displayed by the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function fields(Request $request) { return [ ID::make(__('ID'), 'id')->sortable(), BelongsTo::make('Creator', 'user', 'App\Nova\User') ->onlyOnIndex(), Select::make('Тип пользователя', 'userType')->options([ 1 => 'Физ. лицо', 2 => 'Самозанятый', 3 => 'Юридическое лицо', 4 => 'ИП', ])->displayUsingLabels()->readonly(), Boolean::make('Подписка', function () { $last = $this->user->subscription->first(); if ($last && $last->ends_at > Carbon::now()) { return true; } return false; })->onlyOnIndex(), Files::make('Media Preview', 'preview')->readonly(), Files::make('Media', 'common')->readonly(), Files::make('Media Paid', 'paid')->readonly(), Text::make('Title'), Text::make('Slug')->readonly()->hideFromIndex(), Select::make('Type')->options([ 'images' => 'Изображение', 'musics' => 'Аудио', 'videos' => 'Видео', ])->readonly()->displayUsingLabels(), Text::make('Price')->readonly(), Textarea::make('Body')->alwaysShow()->hideFromIndex(), HasMany::make('Comments'), HasMany::make('Complaints'), DateTime::make('Created At')->format('DD MMM YYYY'), DateTime::make('Updated At')->hideFromIndex(), Text::make('StatusText', function ($model) { if($model->status === StatusEnum::PENDING()){ return 'Нужно проверить'; } if($model->status === StatusEnum::BANNED()){ return 'Рассмотрено - есть проблемы'; } if($model->status === StatusEnum::EDITABLE()){ return 'Нужно повторно рассмотреть'; } })->onlyOnIndex(), Select::make('Status')->options([ (string) StatusEnum::APPROVED() => 'Одобрено', (string) StatusEnum::BANNED() => 'Есть недочеты', ])->hideFromIndex()->displayUsingLabels()->hideWhenCreating(), Textarea::make('Status Note')->hideWhenCreating(), ]; } /** * Get the cards available for the request. * * @param \Illuminate\Http\Request $request * @return array */ public function cards(Request $request) { return []; } /** * Get the filters available for the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function filters(Request $request) { return [ new SubscriptionStatusFilter(), ]; } /** * Get the lenses available for the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function lenses(Request $request) { return []; } /** * Get the actions available for the resource. * * @param \Illuminate\Http\Request $request * @return array */ public function actions(Request $request) { return []; } }