[WIP] Refactor architecture, models
This commit is contained in:
@@ -21,7 +21,7 @@ class Genres
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Family::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
return Genre::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -19,6 +19,11 @@ class Species
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Specie::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Specie::orderBy('name','asc')->get();
|
||||
|
||||
54
app/Repositories/Botanic/Varieties.php
Normal file
54
app/Repositories/Botanic/Varieties.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Botanic;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Botanic\Variety;
|
||||
|
||||
class Varieties
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Variety::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Variety::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variety::find($id);
|
||||
}
|
||||
|
||||
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 Variety::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Variety::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Variety::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,55 +2,63 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Categorie;
|
||||
use App\Models\Shop\Category;
|
||||
|
||||
class Categories
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Categorie::orderBy('name');
|
||||
$model = Category::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Categorie::orderBy('name','asc')->get();
|
||||
return Category::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Categorie::find($id);
|
||||
return Category::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
app('rinvex.categories.category')->create(['name' => $data['name']]);
|
||||
return Categorie::create($data);
|
||||
$node = CategoryTrees::create($data);
|
||||
$data['category_id'] = $node->id;
|
||||
dump($data);
|
||||
$category = Category::create($data);
|
||||
exit;
|
||||
return $category;
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
app('rinvex.categories.category')->update(['name' => $data['name']]);
|
||||
return Categorie::find($id)->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$category = Category::find($id)->update($data);
|
||||
CategoryTrees::update($data, $category->category_id);
|
||||
return $category;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Categorie::destroy($id);
|
||||
// $category = self::get($id);
|
||||
// self::deleteNode($category->category_id);
|
||||
return Category::destroy($id);
|
||||
}
|
||||
|
||||
public static function getRoot()
|
||||
{
|
||||
return app('rinvex.categorys.category')->find(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
39
app/Repositories/Shop/CategoryTrees.php
Normal file
39
app/Repositories/Shop/CategoryTrees.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Category;
|
||||
|
||||
class CategoryTrees
|
||||
{
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$parent = (isset($data['category_id']) && $data['category_id']) ? self::getNode($data['category_id']) : self::getRoot();
|
||||
$category = app('rinvex.categories.category')->create(['name' => $data['name']]);
|
||||
$category->appendToNode($parent)->save();
|
||||
return $category;
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['category_id'];
|
||||
return self::getNode($id)->update(['name' => $data['name']]);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
// return Category::destroy($id);
|
||||
}
|
||||
|
||||
public static function getRoot()
|
||||
{
|
||||
return self::getNode(1);
|
||||
}
|
||||
|
||||
public static function getNode($id)
|
||||
{
|
||||
return app('rinvex.categories.category')->find($id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user