ClearBowl/api/app/Repositories/ProductsRepository.php

36 lines
740 B
PHP
Raw Normal View History

2019-12-04 12:49:41 +01:00
<?php
namespace App\Repositories;
use App\Models\Product;
class ProductsRepository implements ProductsRepositoryInterface
{
public function create($data)
{
return Product::create($data);
}
2019-12-05 10:25:36 +01:00
2019-12-15 21:09:14 +01:00
public function paginate(array $filters)
2019-12-05 10:25:36 +01:00
{
2019-12-15 21:09:14 +01:00
$query = Product::query();
if(isset($filters['search'])){
2019-12-15 21:47:11 +01:00
$search = ucfirst($filters['search']);
$query->where('name', 'like', "${search}%");
2019-12-15 21:09:14 +01:00
}
return $query->paginate($filters['limit']);
2019-12-05 10:25:36 +01:00
}
public function fillProductsInfo(array $products)
{
foreach ($products as $k => $product){
$products[$k]['product'] = Product::find($product['id']);
}
return $products;
}
2019-12-04 12:49:41 +01:00
}