Add categories for generic prices
This commit is contained in:
61
app/Repositories/Shop/PriceGenericCategories.php
Normal file
61
app/Repositories/Shop/PriceGenericCategories.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\PriceGenericCategory;
|
||||
|
||||
class PriceGenericCategories
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = PriceGenericCategory::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceGenericCategory::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceGenericCategory::find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return PriceGenericCategory::get()->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$category = $id ? self::update($data) : self::create($data);
|
||||
return $category->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceGenericCategory::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$category = PriceGenericCategory::find($id);
|
||||
$category->update($data);
|
||||
return $category;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return PriceGenericCategory::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,15 @@ class PriceGenericValues
|
||||
return PriceGenericValue::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($generic_id, $values)
|
||||
{
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$value['price_generic_id'] = $generic_id;
|
||||
self::store($value);
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
|
||||
@@ -36,14 +36,17 @@ class PriceGenerics
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceGeneric::find($id);
|
||||
return PriceGeneric::with("values")->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;
|
||||
$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)
|
||||
@@ -54,9 +57,9 @@ class PriceGenerics
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$article = PriceGeneric::find($id);
|
||||
$article->update($data);
|
||||
return $article;
|
||||
$generic = PriceGeneric::find($id);
|
||||
$generic->update($data);
|
||||
return $generic;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
|
||||
Reference in New Issue
Block a user