71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
use Yajra\DataTables\DataTables;
|
|
|
|
use App\Models\Shop\PriceGeneric;
|
|
|
|
class PriceGenerics
|
|
{
|
|
|
|
public static function getByArticle($id)
|
|
{
|
|
return PriceGeneric::byArticle($id)->get();
|
|
}
|
|
|
|
public static function getByArticleWithValues($id)
|
|
{
|
|
return PriceGeneric::with('values')->byArticle($id)->get();
|
|
}
|
|
|
|
public static function getDatatable()
|
|
{
|
|
$model = PriceGeneric::orderBy('name');
|
|
return Datatables::of($model)->make(true);
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return PriceGeneric::orderBy('name','asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return PriceGeneric::with("values")->find($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$prices = isset($data['prices']) ? $data['prices'] : false;
|
|
unset($data['prices']);
|
|
$generic = $id ? self::update($data) : self::create($data);
|
|
PriceGenericValues::storePrices($generic->id, $prices);
|
|
return $generic->id;
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return PriceGeneric::create($data);
|
|
}
|
|
|
|
public static function update($data, $id = false)
|
|
{
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$generic = PriceGeneric::find($id);
|
|
$generic->update($data);
|
|
return $generic;
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return PriceGeneric::destroy($id);
|
|
}
|
|
|
|
}
|