[WIP] Fix on prices & attributes
This commit is contained in:
@@ -60,6 +60,24 @@ class Articles
|
||||
return Article::find($id);
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$categories = isset($data['categories']) ? $data['categories'] : false;
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
unset($data['images']);
|
||||
unset($data['categories']);
|
||||
unset($data['tags']);
|
||||
unset($data['prices']);
|
||||
$article = self::store($data);
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
self::storePrices($article, $prices);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
@@ -86,21 +104,24 @@ class Articles
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if ($categories)
|
||||
{
|
||||
if ($categories) {
|
||||
$categories = collect($categories)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->attachCategories($categories);
|
||||
} else return false;
|
||||
return $article->syncCategories($categories, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
if ($tags)
|
||||
{
|
||||
return $article->attachTags($tags);
|
||||
}
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->syncTags($tags, true);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
|
||||
Reference in New Issue
Block a user