[WIP] Refactor models to better lisibility and speed

This commit is contained in:
Ludovic CANDELLIER
2020-08-24 01:14:54 +02:00
parent 77a239fce9
commit 3b6108b449
22 changed files with 351 additions and 400 deletions

View File

@@ -0,0 +1,76 @@
<?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\Article;
use App\Models\Shop\Price;
class Prices
{
public static function getByArticle($id)
{
$prices = Article::byArticle($id)->with('prices.price')->get()->pluck('prices')->toArray()[0];
// dump($prices);
$data = [];
foreach ($prices as $price)
{
if ($price['price_type'] == 'App\Models\Shop\ArticlePrice')
{
$data[] = $price['price'];
} else {
$values = PriceGenericValues::getByPriceGeneric($price['price']['id'])->toArray();
foreach ($values as $value)
{
$data[] = $value;
}
}
}
dump($data);
}
public static function getDatatable()
{
$model = Price::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return Price::orderBy('name','asc')->get();
}
public static function get($id)
{
return Price::find($id);
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return Price::create($data);
}
public static function update($data)
{
return Price::find($id)->update($data);
}
public static function destroy($id)
{
return Price::destroy($id);
}
}