Add new version in repository
This commit is contained in:
70
app/Repositories/Shop/PriceLists.php
Normal file
70
app/Repositories/Shop/PriceLists.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Shop\PriceList;
|
||||
|
||||
class PriceLists
|
||||
{
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return PriceList::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithValues($id)
|
||||
{
|
||||
return PriceList::with('values')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return PriceList::with('prices')->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceList::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceList::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return PriceList::with(['price_list_values'])->find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$price_list_values = $data['price_list_values'] ?? false;
|
||||
unset($data['price_list_values']);
|
||||
$price_list = $id ? self::update($data) : self::create($data);
|
||||
PriceListValues::storePrices($price_list->id, $price_list_values);
|
||||
return $price_list;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceList::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 PriceList::destroy($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user