46 lines
995 B
PHP
46 lines
995 B
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Order;
|
|
|
|
class Orders
|
|
{
|
|
|
|
public static function saveOrder($data)
|
|
{
|
|
$basket = $data['basket'];
|
|
unset($data['basket']);
|
|
$order = self::store($data);
|
|
return $order ? OrderDetails::saveBasket($order->id, $basket) : false;
|
|
}
|
|
|
|
public static function get($id, $relations = false)
|
|
{
|
|
return $relations ? Order::with($relations)->findOrFail($id) : Order::findOrFail($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return Order::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 Order::destroy($id);
|
|
}
|
|
}
|