*/ public static $model = OrderItemModel::class; /** * The single value that should be used to represent the resource when being displayed. * * @var string */ public static $title = 'id'; /** * The columns that should be searched. * * @var array */ public static $search = [ 'id', ]; /** * The relationships that should be eager loaded on index queries. * * @var array */ // public static $with = ['product', 'product.media']; /** * The number of resources to show per page via relationships. * * @var int */ public static $perPageViaRelationship = 20; /** * Build an "index" query for the given resource. * * @param Builder $query */ public static function indexQuery(NovaRequest $request, $query): Builder { $user = $request->user(); if ($user->hasRole('vendor')) { $query->with(['product', 'product.media']) ->where('channel_id', $request->user()->channel()->id); } else { $query->with(['product', 'product.media', 'channel']); } return $query; } /** * Get the fields for index. */ public function fieldsForIndex(NovaRequest $request): array { return OrderItemFieldsForIndex::make($this, $request); } /** * Get the fields for create. */ public function fieldsForCreate(NovaRequest $request): array { return OrderItemFieldsForCreate::make($this, $request); } /** * Get the fields displayed by the resource on detail page. */ public function fieldsForUpdate(NovaRequest $request): array { return OrderItemFieldsForUpdate::make($this, $request); } /** * Return the location to redirect the user after creation. * * @param \Laravel\Nova\Resource $resource * @return URL|string */ public static function redirectAfterCreate(NovaRequest $request, $resource) { return sprintf('/resources/orders/%s', $resource->order_id); } /** * Return the location to redirect the user after update. * * @param \Laravel\Nova\Resource $resource * @return URL|string */ public static function redirectAfterUpdate(NovaRequest $request, $resource) { return sprintf('/resources/orders/%s', $resource->order_id); } /** * Get the fields displayed by the resource. */ public function fields(NovaRequest $request): array { return [ ID::make()->sortable(), Text::make(__('Quantity'), 'quantity'), BelongsTo::make(__('Order'), 'order', Order::class), ]; } /** * Get the cards available for the request. * * @return array */ public function cards(NovaRequest $request) { return []; } /** * Get the filters available for the resource. * * @return array */ public function filters(NovaRequest $request) { return []; } /** * Get the lenses available for the resource. * * @return array */ public function lenses(NovaRequest $request) { return []; } /** * Get the actions available for the resource. * * @return array */ public function actions(NovaRequest $request) { return []; } }