Enhance categories, add tags, parent
This commit is contained in:
@@ -130,13 +130,17 @@ class Articles
|
||||
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']);
|
||||
|
||||
$categories = isset($data['categories']) ? $data['categories'] : false;
|
||||
unset($data['categories']);
|
||||
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
unset($data['tags']);
|
||||
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
unset($data['prices']);
|
||||
|
||||
$article = self::store($data);
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
|
||||
@@ -2,18 +2,10 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Category;
|
||||
|
||||
class Categories
|
||||
{
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Category::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Category::orderBy('name', 'asc')->get();
|
||||
@@ -21,7 +13,7 @@ class Categories
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Category::find($id);
|
||||
return Category::with('CategoryTree')->find($id);
|
||||
}
|
||||
|
||||
public static function getTree()
|
||||
@@ -37,12 +29,14 @@ class Categories
|
||||
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']);
|
||||
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
unset($data['tags']);
|
||||
|
||||
$category = self::store($data);
|
||||
self::storeImages($category, $images);
|
||||
// self::storeTags($category, $tags);
|
||||
self::storeTags($category, $tags);
|
||||
return $category;
|
||||
}
|
||||
|
||||
@@ -126,8 +120,8 @@ class Categories
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
// $category = self::get($id);
|
||||
// self::deleteNode($category->category_id);
|
||||
$category = self::get($id);
|
||||
self::deleteNode($category->category_id);
|
||||
return Category::destroy($id);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Category;
|
||||
|
||||
class CategoryTrees
|
||||
{
|
||||
public static function getTree()
|
||||
@@ -50,7 +48,7 @@ class CategoryTrees
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$parent = (isset($data['category_id']) && $data['category_id']) ? self::getNode($data['category_id']) : self::getRoot();
|
||||
$parent = (isset($data['parent_id']) && $data['parent_id']) ? self::getNode($data['parent_id']) : self::getRoot();
|
||||
$category = app('rinvex.categories.category')->create(['name' => $data['name']]);
|
||||
$category->appendToNode($parent)->save();
|
||||
return $category;
|
||||
|
||||
Reference in New Issue
Block a user