*/ public static $model = UserModel::class; /** * The relationships that should be eager loaded on index queries. * * @var array */ public static $with = ['roles']; /** * Get the value that should be displayed to represent the resource. */ public function title(): string { return $this->fullname; } /** * Indicates if the resource should be globally searchable. * * @var bool */ public static $globallySearchable = true; /** * The columns that should be searched. * * @var array */ public static $search = [ 'id', 'first_name', 'last_name', 'phone_number', 'email', ]; /** * Get the displayable label of the resource. */ public static function label(): string { return __('Sellers'); } /** * Get the displayable singular label of the resource. */ public static function singularLabel(): string { return __('Seller'); } /** * Build an "index" query for the given resource. * * @param \Illuminate\Database\Eloquent\Builder $query */ public static function indexQuery(NovaRequest $request, $query): Builder { return $query->join('model_has_roles', 'id', '=', 'model_id')->where('role_id', RoleRepository::make()->vendorId()); } /** * Get the fields displayed by the resource on index page. */ public function fieldsForIndex(NovaRequest $request): array { return [ ID::make()->sortable(), Text::make(__('Name'), 'fullname')->sortable(), Text::make(__('Phone'), 'phone_number')->sortable(), Text::make(__('Email'), 'email')->sortable(), Text::make(__('Roles'), 'role_names'), Boolean::make(__('Verified'), 'verified')->sortable(), ]; } /** * Get the fields displayed by the resource. */ public function fields(NovaRequest $request): array { return [ Text::make(__('First name'), 'first_name') ->rules('required', 'string', 'max:255'), Text::make(__('Last name'), 'last_name') ->rules('required', 'string', 'max:255'), Text::make(__('Email'), 'email') ->rules('required', 'string', 'max:255') ->creationRules('unique:users,email') ->updateRules('unique:users,email,{{resourceId}}'), NovaInputmask::make(__('Phone'), 'phone_number') ->mask(phoneMaskFormat()) ->storeRawValue() ->phoneNumberRule() ->canSeeWhen('systemUser', $this) ->sortable(), Boolean::make(__('Verified'), 'verified') ->default(true), Password::make(__('Password'), 'password') ->onlyOnForms() ->creationRules('required', Rules\Password::defaults()) ->updateRules('nullable', Rules\Password::defaults()), DateTime::make(__('Created at'), 'created_at') ->displayUsing(fn ($value) => $value?->format('H:i, d.m.Y')) ->exceptOnForms(), HasOne::make(__('Documents'), 'documents', UserDocResource::class), MorphToMany::make(__('Roles'), 'roles', Role::class), MorphMany::make(__('Channels'), 'channels', Channel::class), ]; } /** * Get the cards available for the request. */ public function cards(NovaRequest $request): array { return []; } /** * Get the filters available for the resource. */ public function filters(NovaRequest $request): array { return [ new UserRoleFilter, new VerifiedUsersFilter, ]; } /** * Get the lenses available for the resource. */ public function lenses(NovaRequest $request): array { return []; } /** * Get the actions available for the resource. */ public function actions(NovaRequest $request): array { return []; } }