Files
opensem/app/Repositories/Shop/ArticleAttributes.php
2020-06-15 00:17:15 +02:00

66 lines
1.5 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)
{
self::storeAttribute($article_price_id, $attributes[$key]);
}
}
public static function storeAttribute($article_price_id, $attribute)
{
$attribute['article_price_id'] = $article_price_id;
unset($attribute['attribute_family_id']);
return self::store($attribute);
}
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);
}
}