From 7023663e6570f8b5b397caf990e4b12a3917455a Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 12 Jun 2024 16:14:23 -0400 Subject: [PATCH 1/5] Searchable warehouses --- graphql/schemas/Inventory/warehouse.graphql | 1 + .../Warehouses/Models/Warehouses.php | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/graphql/schemas/Inventory/warehouse.graphql b/graphql/schemas/Inventory/warehouse.graphql index 100c9af2c..e07e7fb39 100644 --- a/graphql/schemas/Inventory/warehouse.graphql +++ b/graphql/schemas/Inventory/warehouse.graphql @@ -62,6 +62,7 @@ extend type Mutation @guard { } extend type Query @guard { warehouses( + search: String @search where: _ @whereConditions( columns: [ diff --git a/src/Domains/Inventory/Warehouses/Models/Warehouses.php b/src/Domains/Inventory/Warehouses/Models/Warehouses.php index 1133330ce..e50c9ab36 100644 --- a/src/Domains/Inventory/Warehouses/Models/Warehouses.php +++ b/src/Domains/Inventory/Warehouses/Models/Warehouses.php @@ -13,6 +13,9 @@ use Kanvas\Inventory\Regions\Models\Regions; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\VariantsWarehouses; +use Laravel\Scout\EngineManager; +use Laravel\Scout\Engines\Engine; +use Laravel\Scout\Searchable; /** * Class Warehouses. @@ -35,6 +38,9 @@ class Warehouses extends BaseModel { use UuidTrait; use DefaultTrait; + use Searchable { + search as public traitSearch; + } protected $table = 'warehouses'; @@ -204,4 +210,24 @@ public function setTotalProducts(): int return 0; } + + /** + * Get the engine used to index the model. + */ + public function searchableUsing(): Engine + { + return app(EngineManager::class)->engine('database'); + } + + public function toSearchableArray(): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'uuid' => $this->uuid, + 'regions_id' => $this->regions_id, + 'location' => $this->location, + 'is_published' => $this->is_published, + ]; + } } From 63e709bf1a08d3dbec2f284956514dfc89dea987 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 12 Jun 2024 16:48:04 -0400 Subject: [PATCH 2/5] Add searchable directive --- graphql/schemas/Inventory/attributes.graphql | 1 + graphql/schemas/Inventory/category.graphql | 1 + graphql/schemas/Inventory/channel.graphql | 1 + graphql/schemas/Inventory/productType.graphql | 1 + graphql/schemas/Inventory/status.graphql | 1 + 5 files changed, 5 insertions(+) diff --git a/graphql/schemas/Inventory/attributes.graphql b/graphql/schemas/Inventory/attributes.graphql index 8a2f62264..83dc2a3bd 100644 --- a/graphql/schemas/Inventory/attributes.graphql +++ b/graphql/schemas/Inventory/attributes.graphql @@ -67,6 +67,7 @@ extend type Mutation @guard { } extend type Query @guard { attributes( + search: String @search where: _ @whereConditions( columns: [ diff --git a/graphql/schemas/Inventory/category.graphql b/graphql/schemas/Inventory/category.graphql index 62ab4bc25..006f94b0a 100644 --- a/graphql/schemas/Inventory/category.graphql +++ b/graphql/schemas/Inventory/category.graphql @@ -54,6 +54,7 @@ extend type Mutation @guard { extend type Query @guard { categories( + search: String @search where: _ @whereConditions( columns: [ diff --git a/graphql/schemas/Inventory/channel.graphql b/graphql/schemas/Inventory/channel.graphql index a99096a5a..4e0f33320 100644 --- a/graphql/schemas/Inventory/channel.graphql +++ b/graphql/schemas/Inventory/channel.graphql @@ -48,6 +48,7 @@ extend type Mutation @guard { } extend type Query @guard { channels( + search: String @search where: _ @whereConditions( columns: [ diff --git a/graphql/schemas/Inventory/productType.graphql b/graphql/schemas/Inventory/productType.graphql index bda707e31..2a221a0fd 100644 --- a/graphql/schemas/Inventory/productType.graphql +++ b/graphql/schemas/Inventory/productType.graphql @@ -63,6 +63,7 @@ extend type Mutation @guard { } extend type Query { productTypes( + search: String @search where: _ @whereConditions( columns: [ diff --git a/graphql/schemas/Inventory/status.graphql b/graphql/schemas/Inventory/status.graphql index 2a8bb12f6..c48a6d963 100644 --- a/graphql/schemas/Inventory/status.graphql +++ b/graphql/schemas/Inventory/status.graphql @@ -37,6 +37,7 @@ extend type Mutation @guard { extend type Query @guard { status( + search: String @search where: _ @whereConditions( columns: [ From d8f4614a34cc2c8db0a6a4c9566e0fc08e690ca2 Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 12 Jun 2024 16:48:21 -0400 Subject: [PATCH 3/5] Create database searchable engine trait --- .../Traits/DatabaseSearchableTrait.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Domains/Inventory/Traits/DatabaseSearchableTrait.php diff --git a/src/Domains/Inventory/Traits/DatabaseSearchableTrait.php b/src/Domains/Inventory/Traits/DatabaseSearchableTrait.php new file mode 100644 index 000000000..b0b89aeeb --- /dev/null +++ b/src/Domains/Inventory/Traits/DatabaseSearchableTrait.php @@ -0,0 +1,32 @@ +engine('database'); + } + + public function toSearchableArray(): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + ]; + } +} From 5880d3410ea5b0c278cdf00894ecaf48eefc270b Mon Sep 17 00:00:00 2001 From: arfenis Date: Wed, 12 Jun 2024 16:48:49 -0400 Subject: [PATCH 4/5] Add searchable trait to entities --- .../Attributes/Models/Attributes.php | 2 ++ .../Categories/Models/Categories.php | 2 ++ .../Inventory/Channels/Models/Channels.php | 2 ++ .../ProductsTypes/Models/ProductsTypes.php | 2 ++ .../Inventory/Status/Models/Status.php | 3 +- .../Warehouses/Models/Warehouses.php | 28 ++----------------- 6 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index afa033285..b6885efb5 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -12,6 +12,7 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Inventory\Models\BaseModel; +use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Variants\Models\VariantsAttributes; /** @@ -27,6 +28,7 @@ class Attributes extends BaseModel { use UuidTrait; use CascadeSoftDeletes; + use DatabaseSearchableTrait; public $table = 'attributes'; public $guarded = []; diff --git a/src/Domains/Inventory/Categories/Models/Categories.php b/src/Domains/Inventory/Categories/Models/Categories.php index cb717b6b5..2dbeb1ff8 100644 --- a/src/Domains/Inventory/Categories/Models/Categories.php +++ b/src/Domains/Inventory/Categories/Models/Categories.php @@ -12,6 +12,7 @@ use Kanvas\Companies\Models\Companies; use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Products\Models\ProductsCategories; +use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\ScopesTrait; class Categories extends BaseModel @@ -19,6 +20,7 @@ class Categories extends BaseModel use UuidTrait; use SlugTrait; use ScopesTrait; + use DatabaseSearchableTrait; protected $table = 'categories'; protected $guarded = []; diff --git a/src/Domains/Inventory/Channels/Models/Channels.php b/src/Domains/Inventory/Channels/Models/Channels.php index 3dbcf4a57..4539dea78 100644 --- a/src/Domains/Inventory/Channels/Models/Channels.php +++ b/src/Domains/Inventory/Channels/Models/Channels.php @@ -12,6 +12,7 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Inventory\Models\BaseModel; +use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\Variants; use Kanvas\Inventory\Variants\Models\VariantsChannels; @@ -37,6 +38,7 @@ class Channels extends BaseModel { use UuidTrait; use SlugTrait; + use DatabaseSearchableTrait; use DefaultTrait; protected $table = 'channels'; diff --git a/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php b/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php index 75ef48425..3ff2cc504 100644 --- a/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php +++ b/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php @@ -16,6 +16,7 @@ use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Products\Factories\ProductTypeFactory; use Kanvas\Inventory\Products\Models\Products; +use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\ScopesTrait; /** @@ -36,6 +37,7 @@ class ProductsTypes extends BaseModel use UuidTrait; use SlugTrait; use ScopesTrait; + use DatabaseSearchableTrait; use CascadeSoftDeletes; protected $table = 'products_types'; diff --git a/src/Domains/Inventory/Status/Models/Status.php b/src/Domains/Inventory/Status/Models/Status.php index 79501d929..a16555a3c 100644 --- a/src/Domains/Inventory/Status/Models/Status.php +++ b/src/Domains/Inventory/Status/Models/Status.php @@ -7,6 +7,7 @@ use Baka\Traits\SlugTrait; use Illuminate\Database\Eloquent\Relations\HasMany; use Kanvas\Inventory\Models\BaseModel; +use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\Variants; use Kanvas\Inventory\Variants\Models\VariantsWarehouses; @@ -24,7 +25,7 @@ class Status extends BaseModel { use SlugTrait; - //use Searchable; + use DatabaseSearchableTrait; use DefaultTrait; protected $table = 'status'; diff --git a/src/Domains/Inventory/Warehouses/Models/Warehouses.php b/src/Domains/Inventory/Warehouses/Models/Warehouses.php index e50c9ab36..9e94b79e9 100644 --- a/src/Domains/Inventory/Warehouses/Models/Warehouses.php +++ b/src/Domains/Inventory/Warehouses/Models/Warehouses.php @@ -11,11 +11,9 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Regions\Models\Regions; +use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\VariantsWarehouses; -use Laravel\Scout\EngineManager; -use Laravel\Scout\Engines\Engine; -use Laravel\Scout\Searchable; /** * Class Warehouses. @@ -38,9 +36,7 @@ class Warehouses extends BaseModel { use UuidTrait; use DefaultTrait; - use Searchable { - search as public traitSearch; - } + use DatabaseSearchableTrait; protected $table = 'warehouses'; @@ -210,24 +206,4 @@ public function setTotalProducts(): int return 0; } - - /** - * Get the engine used to index the model. - */ - public function searchableUsing(): Engine - { - return app(EngineManager::class)->engine('database'); - } - - public function toSearchableArray(): array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'uuid' => $this->uuid, - 'regions_id' => $this->regions_id, - 'location' => $this->location, - 'is_published' => $this->is_published, - ]; - } } From c7eb40a60ceeebc6160d62d19c66c520227450d4 Mon Sep 17 00:00:00 2001 From: arfenis Date: Thu, 13 Jun 2024 11:15:09 -0400 Subject: [PATCH 5/5] move trait to baka --- .../Inventory => Baka}/Traits/DatabaseSearchableTrait.php | 2 +- src/Domains/Inventory/Attributes/Models/Attributes.php | 2 +- src/Domains/Inventory/Categories/Models/Categories.php | 2 +- src/Domains/Inventory/Channels/Models/Channels.php | 2 +- src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php | 2 +- src/Domains/Inventory/Status/Models/Status.php | 2 +- src/Domains/Inventory/Warehouses/Models/Warehouses.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename src/{Domains/Inventory => Baka}/Traits/DatabaseSearchableTrait.php (94%) diff --git a/src/Domains/Inventory/Traits/DatabaseSearchableTrait.php b/src/Baka/Traits/DatabaseSearchableTrait.php similarity index 94% rename from src/Domains/Inventory/Traits/DatabaseSearchableTrait.php rename to src/Baka/Traits/DatabaseSearchableTrait.php index b0b89aeeb..64239a646 100644 --- a/src/Domains/Inventory/Traits/DatabaseSearchableTrait.php +++ b/src/Baka/Traits/DatabaseSearchableTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Kanvas\Inventory\Traits; +namespace Baka\Traits; use Laravel\Scout\EngineManager; use Laravel\Scout\Engines\Engine; diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index b6885efb5..644a77876 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -12,7 +12,7 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Inventory\Models\BaseModel; -use Kanvas\Inventory\Traits\DatabaseSearchableTrait; +use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Variants\Models\VariantsAttributes; /** diff --git a/src/Domains/Inventory/Categories/Models/Categories.php b/src/Domains/Inventory/Categories/Models/Categories.php index 2dbeb1ff8..080946650 100644 --- a/src/Domains/Inventory/Categories/Models/Categories.php +++ b/src/Domains/Inventory/Categories/Models/Categories.php @@ -12,7 +12,7 @@ use Kanvas\Companies\Models\Companies; use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Products\Models\ProductsCategories; -use Kanvas\Inventory\Traits\DatabaseSearchableTrait; +use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\ScopesTrait; class Categories extends BaseModel diff --git a/src/Domains/Inventory/Channels/Models/Channels.php b/src/Domains/Inventory/Channels/Models/Channels.php index 4539dea78..a10857c82 100644 --- a/src/Domains/Inventory/Channels/Models/Channels.php +++ b/src/Domains/Inventory/Channels/Models/Channels.php @@ -12,7 +12,7 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Inventory\Models\BaseModel; -use Kanvas\Inventory\Traits\DatabaseSearchableTrait; +use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\Variants; use Kanvas\Inventory\Variants\Models\VariantsChannels; diff --git a/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php b/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php index 3ff2cc504..936022192 100644 --- a/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php +++ b/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php @@ -16,7 +16,7 @@ use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Products\Factories\ProductTypeFactory; use Kanvas\Inventory\Products\Models\Products; -use Kanvas\Inventory\Traits\DatabaseSearchableTrait; +use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\ScopesTrait; /** diff --git a/src/Domains/Inventory/Status/Models/Status.php b/src/Domains/Inventory/Status/Models/Status.php index a16555a3c..7b3641164 100644 --- a/src/Domains/Inventory/Status/Models/Status.php +++ b/src/Domains/Inventory/Status/Models/Status.php @@ -7,7 +7,7 @@ use Baka\Traits\SlugTrait; use Illuminate\Database\Eloquent\Relations\HasMany; use Kanvas\Inventory\Models\BaseModel; -use Kanvas\Inventory\Traits\DatabaseSearchableTrait; +use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\Variants; use Kanvas\Inventory\Variants\Models\VariantsWarehouses; diff --git a/src/Domains/Inventory/Warehouses/Models/Warehouses.php b/src/Domains/Inventory/Warehouses/Models/Warehouses.php index 9e94b79e9..09df6e1d0 100644 --- a/src/Domains/Inventory/Warehouses/Models/Warehouses.php +++ b/src/Domains/Inventory/Warehouses/Models/Warehouses.php @@ -4,6 +4,7 @@ namespace Kanvas\Inventory\Warehouses\Models; +use Baka\Traits\DatabaseSearchableTrait; use Baka\Traits\UuidTrait; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -11,7 +12,6 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Regions\Models\Regions; -use Kanvas\Inventory\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; use Kanvas\Inventory\Variants\Models\VariantsWarehouses;