78 lines
1.5 KiB
PHP
78 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
use Yajra\DataTables\DataTables;
|
|
|
|
use App\Models\Shop\ArticlePrice;
|
|
|
|
class ArticlePrices
|
|
{
|
|
|
|
public static function getDatatable()
|
|
{
|
|
$model = ArticlePrice::orderBy('name');
|
|
return Datatables::of($model)->make(true);
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return ArticlePrice::orderBy('name','asc')->get();
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return ArticlePrice::find($id);
|
|
}
|
|
|
|
public static function storePrices($article_id, $prices)
|
|
{
|
|
if ($prices) {
|
|
foreach ($prices as $$key => $price) {
|
|
$prices[$key]['article_id'] = $article_id;
|
|
self::store($prices[$key]);
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static function storeAttributes($article_price_id,$attributes)
|
|
{
|
|
return ArticleAttributes::storeAttributes($article_price_id, $attributes);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$attributes = isset($data['attributes']) ? $data['attributes'] : false;
|
|
unset($data['attributes']);
|
|
|
|
$id = isset($data['id']) ? $data['id'] : false;
|
|
$price = $id ? self::update($data) : self::create($data);
|
|
|
|
$ret = $attributes ? self::storeAttributes($price->id, $attributes) : false;
|
|
|
|
return $price->id;
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return ArticlePrice::create($data);
|
|
}
|
|
|
|
public static function update($data)
|
|
{
|
|
return ArticlePrice::find($id)->update($data);
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return ArticlePrice::destroy($id);
|
|
}
|
|
|
|
}
|