Files
opensem/app/Repositories/Shop/ArticleAttributes.php
2020-06-14 23:30:33 +02:00

61 lines
1.3 KiB
PHP

<?php
namespace App\Repositories\Shop;
use Yajra\DataTables\DataTables;
use App\Models\Shop\ArticleAttribute;
class ArticleAttributes
{
public static function getDatatable()
{
$model = ArticleAttribute::orderBy('name');
return Datatables::of($model)->make(true);
}
public static function getAll()
{
return ArticleAttribute::orderBy('name','asc')->get();
}
public static function get($id)
{
return ArticleAttribute::find($id);
}
public static function storeAttributes($article_price_id, $attributes)
{
foreach ($attributes as $key => $attribute)
{
$attributes[$key]['article_price_id'] = $article_price_id;
unset($attributes[$key]['attribute_family_id']);
self::store($attributes[$key]);
}
}
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 ArticleAttribute::create($data);
}
public static function update($data)
{
return ArticleAttribute::find($id)->update($data);
}
public static function destroy($id)
{
return ArticleAttribute::destroy($id);
}
}