diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php index fb4260d..5654657 100644 --- a/database/factories/ProductFactory.php +++ b/database/factories/ProductFactory.php @@ -4,6 +4,7 @@ use Lunar\FieldTypes\Text; use Lunar\Models\Brand; +use Lunar\Enums\ProductStatus; use Lunar\Models\Product; use Lunar\Models\ProductType; @@ -15,7 +16,7 @@ public function definition(): array { return [ 'product_type_id' => ProductType::factory(), - 'status' => 'published', + 'status' => ProductStatus::Published, 'brand_id' => Brand::factory()->create()->id, 'attribute_data' => collect([ 'name' => new Text($this->faker->name), diff --git a/src/Enums/ProductStatus.php b/src/Enums/ProductStatus.php new file mode 100644 index 0000000..75a95ca --- /dev/null +++ b/src/Enums/ProductStatus.php @@ -0,0 +1,9 @@ + AsAttributeData::class, + 'status' => ProductStatus::class, ]; /** @@ -189,9 +191,11 @@ public function brand(): BelongsTo return $this->belongsTo(Brand::modelClass()); } - public function scopeStatus(Builder $query, string $status): Builder + public function scopeStatus(Builder $query, ProductStatus|string $status): Builder { - return $query->whereStatus($status); + $value = $status instanceof ProductStatus ? $status->value : $status; + + return $query->where('status', $value); } public function prices(): HasManyThrough