update fix deadcode, security
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Customer;
|
||||
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminCustomerRepository implements AdminCustomerRepositoryInterface
|
||||
{
|
||||
private const STATUS_MAP = [
|
||||
'active' => 1,
|
||||
'inactive' => 2,
|
||||
'pending' => 0,
|
||||
'suspended' => 3,
|
||||
];
|
||||
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Customer::query()->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
->orWhere('phone', 'like', "%{$filter}%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($status = $filters['status'] ?? null) {
|
||||
$statusInt = self::STATUS_MAP[$status] ?? null;
|
||||
if ($statusInt !== null) {
|
||||
$query->where('status', $statusInt);
|
||||
}
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Customer;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminCustomerRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Invoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminInvoiceRepository implements AdminInvoiceRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Invoice::with('customer')->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('order_num', 'like', "%{$filter}%")
|
||||
->orWhereHas('customer', fn($q2) =>
|
||||
$q2->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (($status = $filters['status'] ?? null) !== null && $status !== '') {
|
||||
$query->where('status', (int) $status);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Invoice;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminInvoiceRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Order;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class AdminOrderRepository implements AdminOrderRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$query = Order::with('customer')->orderBy('id', 'desc');
|
||||
|
||||
if ($filter = $filters['filter'] ?? null) {
|
||||
$query->where(function ($q) use ($filter) {
|
||||
$q->where('order_num', 'like', "%{$filter}%")
|
||||
->orWhereHas('customer', fn($q2) =>
|
||||
$q2->where('fullname', 'like', "%{$filter}%")
|
||||
->orWhere('email', 'like', "%{$filter}%")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (($status = $filters['status'] ?? null) !== null && $status !== '') {
|
||||
$query->where('status', (int) $status);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Admin\Order;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface AdminOrderRepositoryInterface
|
||||
{
|
||||
public function paginate(array $filters, int $perPage): LengthAwarePaginator;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?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
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user