61 lines
1.2 KiB
PHP
61 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Offer;
|
|
|
|
class Offers
|
|
{
|
|
|
|
public static function getLast()
|
|
{
|
|
return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
|
|
}
|
|
|
|
public static function getByCategory($category_id)
|
|
{
|
|
return Offer::with(['article.image'])->byCategory($category_id)->get();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return Offer::orderBy('value', 'asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return Offer::findOrFail($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$item = $id ? self::update($data, $id) : self::create($data);
|
|
return $item->id;
|
|
}
|
|
|
|
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, $active)
|
|
{
|
|
return self::update(['status_id' => $active], $id);
|
|
}
|
|
|
|
}
|