Skip to content

Commit

Permalink
Add store to Nova (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean authored Mar 13, 2023
1 parent aaf7690 commit 9fad21e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Nova/Filters/StoreFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace JustBetter\MagentoProductsNova\Nova\Filters;

use Illuminate\Database\Eloquent\Builder;
use JustBetter\MagentoProducts\Models\MagentoProduct;
use Laravel\Nova\Filters\Filter;
use Laravel\Nova\Http\Requests\NovaRequest;

class StoreFilter extends Filter
{
public function apply(NovaRequest $request, $query, $value): Builder
{
return $query->where('store', '=', $value);
}

public function options(NovaRequest $request): array
{
return MagentoProduct::query()
->select(['store'])
->distinct()
->get()
->pluck('store', 'store')
->toArray();
}
}
11 changes: 11 additions & 0 deletions src/Nova/MagentoProductsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function fields(Request $request): array
Boolean::make(__('Exists in Magento'), 'exists_in_magento')
->sortable(),

Text::make(__('Store'), 'store')
->readonly()
->sortable(),

Code::make(__('Data'), 'data')
->json(),

Expand All @@ -63,6 +67,13 @@ public function actions(Request $request): array
];
}

public function filters(Request $request): array
{
return [
Filters\StoreFilter::make(),
];
}

public static function authorizedToCreate(Request $request): bool
{
return false;
Expand Down

0 comments on commit 9fad21e

Please sign in to comment.