50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\OrderDetail;
|
|
|
|
class OrderDetails
|
|
{
|
|
public static function saveBasket($order_id, $data)
|
|
{
|
|
foreach ($data as $item) {
|
|
$detail = self::store([
|
|
'order_id' => $order_id,
|
|
'offer_id' => $item['id'],
|
|
'quantity' => $item['quantity'],
|
|
'price_taxed' => $item['price'],
|
|
]);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function get($id, $relations = false)
|
|
{
|
|
return $relations ? OrderDetail::with($relations)->findOrFail($id) : OrderDetail::findOrFail($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return OrderDetail::create($data);
|
|
}
|
|
|
|
public static function update($data, $id = false)
|
|
{
|
|
$id = $id ? $id : $data['id'];
|
|
$item = self::get($id);
|
|
$item->update($data);
|
|
return $item;
|
|
}
|
|
|
|
public static function delete($id)
|
|
{
|
|
return OrderDetail::destroy($id);
|
|
}
|
|
}
|