Files
opensem/app/Repositories/Shop/Deliveries.php
Ludovic CANDELLIER 7df2421373 restart
2022-11-11 13:05:40 +01:00

60 lines
1.3 KiB
PHP

<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Delivery;
class Deliveries
{
public static function getOptions()
{
return Delivery::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
}
public static function getAll($relations = false)
{
$model = $relations ? Delivery::with($relations) : Delivery::query();
return $model->orderBy('name', 'asc')->get();
}
public static function getAllWithSaleChannel()
{
return Delivery::orderBy('name', 'asc')->active()->public()->with('sale_channel')->get();
}
public static function get($id)
{
return Delivery::find($id);
}
public static function store($data)
{
$id = $data['id'] ?? false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
public static function create($data)
{
return Delivery::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$delivery = self::get($id);
$delivery->update($data);
return $delivery;
}
public static function destroy($id)
{
return Delivery::destroy($id);
}
public static function toggle_active($id, $active)
{
return self::update(['active' => $active], $id);
}
}