[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,67 @@
<?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::find($id);
}
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 PriceGeneric::create($data);
}
public static function update($data, $id = false)
{
$id = isset($data['id']) ? $data['id'] : false;
$article = PriceGeneric::find($id);
$article->update($data);
return $article;
}
public static function destroy($id)
{
return PriceGeneric::destroy($id);
}
}