feat(category-visibility): implement category visibility controller and service with update functionality
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\FiestaFutbolInfantil\Services;
|
||||
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\FiestaFutbolInfantil\Enums\FiestaCategory;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
|
||||
class CategoryVisibilityService
|
||||
{
|
||||
public function isEnabled(Tenant $tenant, FiestaCategory $category): bool
|
||||
{
|
||||
return Category::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('nombre', $category->categoryName())
|
||||
->value('is_enabled') ?? true;
|
||||
}
|
||||
|
||||
public function update(Tenant $tenant, FiestaCategory $category, bool $isEnabled): Category
|
||||
{
|
||||
$model = Category::query()->firstOrCreate([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => $category->categoryName(),
|
||||
]);
|
||||
$model->update(['is_enabled' => $isEnabled]);
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user