65 lines
1.3 KiB
PHP
65 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\SaleChannel;
|
|
|
|
class SaleChannels
|
|
{
|
|
public static function getDefaultID()
|
|
{
|
|
$default = self::getDefault();
|
|
return $default ? self::getDefault()->id : false;
|
|
}
|
|
|
|
public static function getDefault()
|
|
{
|
|
return self::getByCode('EXP');
|
|
}
|
|
|
|
public static function getByCode($code)
|
|
{
|
|
return SaleChannel::byCode($code)->first();
|
|
}
|
|
|
|
public static function getOptions()
|
|
{
|
|
return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return SaleChannel::orderBy('name', 'asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return SaleChannel::findOrFail($id);
|
|
}
|
|
|
|
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 SaleChannel::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 SaleChannel::destroy($id);
|
|
}
|
|
}
|