[WIP] Refactor models to better lisibility and speed
This commit is contained in:
67
app/Repositories/Shop/PriceGenerics.php
Normal file
67
app/Repositories/Shop/PriceGenerics.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user