add validator, optimizations
This commit is contained in:
@@ -3,12 +3,19 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Offers
|
||||
{
|
||||
public static function count()
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return Offer::count();
|
||||
return [
|
||||
'articles' => Articles::getOptionsWithNature(),
|
||||
'tariffs' => Tariffs::getOptions(),
|
||||
'variations' => Variations::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getWeight($id, $quantity = 1)
|
||||
@@ -116,42 +123,13 @@ class Offers
|
||||
return Offer::with(['article.tags'])->byTags($tags)->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Offer::get();
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return $relations ? Offer::with($relations)->findOrFail($id) : Offer::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Offer::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Offer::destroy($id);
|
||||
}
|
||||
|
||||
public static function toggle_active($id, $status_id)
|
||||
{
|
||||
return self::update(['status_id' => $status_id], $id);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Offer::query();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user