feat: Implement product and product category management with dedicated CRUD operations, services, and repositories.
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\ProductCategory;
|
||||
|
||||
use App\Models\ProductCategories;
|
||||
use App\Repositories\BaseRepository;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ProductCategoryRepository extends BaseRepository implements ProductCategoryRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ProductCategories::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\ProductCategory;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface ProductCategoryRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user