48 lines
1012 B
PHP
48 lines
1012 B
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\OrderDetail;
|
|
|
|
class OrderDetails
|
|
{
|
|
public static function saveBasket($order_id, $data)
|
|
{
|
|
foreach ($data as $item) {
|
|
$item['order_id'] = $order_id;
|
|
$detail = self::store($item);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|