Fixes on categories
This commit is contained in:
@@ -35,12 +35,70 @@ class Categories
|
||||
return Category::get()->pluck('name','category_id')->toArray();
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
// $tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
unset($data['images']);
|
||||
// unset($data['tags']);
|
||||
$category = self::store($data);
|
||||
self::storeImages($category, $images);
|
||||
// self::storeTags($category, $tags);
|
||||
return $category;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function storeTags($category, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $category->syncTags($tags, true);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static function storeImages($category, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($category, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($category, $file)
|
||||
{
|
||||
return $article->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$category = self::get($id);
|
||||
if ($category) {
|
||||
$category->getMedia();
|
||||
foreach ($category->media as $key => $media) {
|
||||
$category->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $category->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
$category = self::get($id);
|
||||
$category->getMedia();
|
||||
$ret = $category->media[$index]->delete();
|
||||
return "1";
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$node = CategoryTrees::create($data);
|
||||
@@ -52,7 +110,8 @@ class Categories
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$category = Category::find($id)->update($data);
|
||||
$category = Category::find($id);
|
||||
$ret = $category->update($data);
|
||||
CategoryTrees::update($data, $category->category_id);
|
||||
return $category;
|
||||
}
|
||||
@@ -66,7 +125,7 @@ class Categories
|
||||
|
||||
public static function getRoot()
|
||||
{
|
||||
return app('rinvex.categorys.category')->find(1);
|
||||
return app('rinvex.categories.category')->find(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user