first change
This commit is contained in:
60
Modules/Product/app/Repositories/ProductRepository.php
Normal file
60
Modules/Product/app/Repositories/ProductRepository.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Product\Repositories;
|
||||
|
||||
use Modules\Product\Interfaces\ProductInterface;
|
||||
use Modules\Product\Models\Product;
|
||||
|
||||
class ProductRepository implements ProductInterface
|
||||
{
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
return Product::get();
|
||||
}
|
||||
|
||||
public function getProductById($productId)
|
||||
{
|
||||
return Product::findOrFail($productId);
|
||||
}
|
||||
|
||||
public function getProductList()
|
||||
{
|
||||
$products = Product::with('client:id,name')->get();
|
||||
|
||||
$keyed = $products->mapWithKeys(function (Product $item) {
|
||||
return [$item->id => $item->name.' ('.$item->client?->name.')'];
|
||||
});
|
||||
|
||||
return $keyed->all();
|
||||
}
|
||||
|
||||
public function create(array $productDetails)
|
||||
{
|
||||
return Product::create($productDetails);
|
||||
}
|
||||
|
||||
public function update($productId, array $newDetails)
|
||||
{
|
||||
return Product::whereId($productId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function delete($productId)
|
||||
{
|
||||
return Product::destroy($productId);
|
||||
}
|
||||
public function pluck()
|
||||
{
|
||||
return Product::pluck('name', 'id');
|
||||
}
|
||||
public function count()
|
||||
{
|
||||
return Product::count();
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return Product::with('client');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user