[WIP] Refactor models to better lisibility and speed
This commit is contained in:
67
app/Repositories/Shop/PriceFamilyValues.php
Normal file
67
app/Repositories/Shop/PriceFamilyValues.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\PriceFamilyValue;
|
||||
|
||||
class PriceFamilyValues
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = PriceFamilyValue::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceFamilyValue::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceFamilyValue::find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return PriceFamilyValue::get()->pluck('value','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getSelectByFamily($family_id)
|
||||
{
|
||||
// return PriceFamilyValue::byFamily($attribute_family_id)->get()->pluck('value','id')->toArray();
|
||||
$values = PriceFamilyValue::byFamily($family_id)->get();
|
||||
$data = [];
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$data[] = ['id' => $value->id, 'text' => $value->value];
|
||||
}
|
||||
return collect($data)->sortBy('text')->values()->all();
|
||||
}
|
||||
|
||||
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 PriceFamilyValue::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return PriceFamilyValue::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return PriceFamilyValue::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user