feat: Implement product and product category management with dedicated CRUD operations, services, and repositories.

This commit is contained in:
pbao9
2026-02-06 11:05:18 +07:00
parent eef04846a8
commit 92151261b3
61 changed files with 2331 additions and 656 deletions
@@ -0,0 +1,63 @@
<?php
namespace App\Repositories\Admin\Product;
use App\Models\Product;
use App\Repositories\BaseRepository;
use Illuminate\Support\Str;
class ProductRepository extends BaseRepository implements ProductRepositoryInterface
{
public function getModel()
{
return Product::class;
}
public function create(array $data = [])
{
if (empty($data['slug']) && !empty($data['name'])) {
$data['slug'] = Str::slug($data['name']);
}
return parent::create($data);
}
public function update(int $id = 0, array $data = [])
{
if (isset($data['name']) && empty($data['slug'])) {
$data['slug'] = Str::slug($data['name']);
}
return parent::update($id, $data);
}
public function filter(
array $data = [],
array $relationships = [],
array $withCount = [],
array $select = ['*'],
bool $returnQuery = false
) {
$query = $this->model
->select($select)
->with($relationships);
// if (!empty($data['vcenter_id'])) {
// $query->where('vcenter_id', $data['vcenter_id']);
// }
if (!empty($withCount)) {
$query->withCount($withCount);
}
if ($returnQuery) {
return $query;
}
if (!empty($data['paginate'])) {
return $query->paginate(
$data['per_page'] ?? 15
);
}
return $query->get();
}
}
@@ -0,0 +1,16 @@
<?php
namespace App\Repositories\Admin\Product;
use App\Repositories\BaseRepositoryInterface;
interface ProductRepositoryInterface extends BaseRepositoryInterface
{
public function filter(
array $data = [],
array $relationships = [],
array $withCount = [],
array $select = ['*'],
bool $returnQuery = false
);
}