Files
opensem/app/Repositories/Shop/PriceListValues.php
2021-07-25 23:19:27 +02:00

68 lines
1.5 KiB
PHP

<?php
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\PriceListValue;
class PriceListValues
{
public static function getByPriceListValue($id)
{
return PriceListValue::byPriceListValue($id)->get();
}
public static function getDatatable()
{
$model = PriceListValue::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return PriceListValue::orderBy('name', 'asc')->get();
}
public static function get($id)
{
return PriceListValue::find($id);
}
public static function storePrices($generic_id, $values)
{
foreach ($values as $value) {
$value['price_generic_id'] = $generic_id;
self::store($value);
}
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data);
return $price->id;
}
public static function create($data)
{
return PriceListValue::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 destroy($id)
{
return PriceListValue::destroy($id);
}
}