[WIP] Refactor architecture, models
This commit is contained in:
@@ -41,6 +41,7 @@ class migrate extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/*
|
||||
$varieties = Variety::all();
|
||||
foreach ($varieties as $variety) {
|
||||
$specie_name = $variety->specie;
|
||||
@@ -59,7 +60,7 @@ class migrate extends Command
|
||||
dump("Aucune espèce");
|
||||
}
|
||||
}
|
||||
/*
|
||||
*/
|
||||
$species = Specie::all();
|
||||
foreach ($species as $specie) {
|
||||
$genre_name = $specie->genre;
|
||||
@@ -78,8 +79,8 @@ class migrate extends Command
|
||||
dump("Aucun genre");
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
/*
|
||||
$genres = Genre::all();
|
||||
foreach ($genres as $genre) {
|
||||
$family_name = $genre->family;
|
||||
|
||||
@@ -23,7 +23,7 @@ class GenresDataTable extends DataTable
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::make('family.name'),
|
||||
Column::make('species_count')->title('Nb Espèces'),
|
||||
Column::make('species_count')->title('Nb Espèces')->searchable(false),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
|
||||
@@ -21,9 +21,9 @@ class SpeciesDataTable extends DataTable
|
||||
return [
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('alias'),
|
||||
Column::make('genre_name'),
|
||||
Column::make('genre.name'),
|
||||
Column::make('latin'),
|
||||
Column::make('varieties_count')->title('Nb variétés'),
|
||||
Column::make('varieties_count')->title('Nb variétés')->searchable(false),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
|
||||
@@ -19,8 +19,8 @@ class VarietiesDataTable extends DataTable
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('specie_name'),
|
||||
Column::make('name'),
|
||||
Column::make('specie_name')->title('Espèce'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
namespace App\DataTables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\DataTables\ParentDataTable as DataTable;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
namespace App\DataTables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\DataTables\ParentDataTable as DataTable;
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
namespace App\DataTables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\DataTables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Product;
|
||||
use App\Models\Shop\Customer;
|
||||
|
||||
class ProductsDataTable extends DataTable
|
||||
class CustomersDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'Products';
|
||||
public $model_name = 'Customers';
|
||||
|
||||
public function query(Product $model)
|
||||
{
|
||||
@@ -19,8 +19,6 @@ class ProductsDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
namespace App\DataTables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\DataTables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Product;
|
||||
use App\Models\Shop\Invoice;
|
||||
|
||||
class ProductsDataTable extends DataTable
|
||||
class InvoicesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'Products';
|
||||
public $model_name = 'Invoices';
|
||||
|
||||
public function query(Product $model)
|
||||
{
|
||||
@@ -19,8 +19,6 @@ class ProductsDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
namespace App\DataTables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\DataTables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Product;
|
||||
use App\Models\Shop\Order;
|
||||
|
||||
class ProductsDataTable extends DataTable
|
||||
class OrdersDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'Products';
|
||||
public $model_name = 'Orders';
|
||||
|
||||
public function query(Product $model)
|
||||
{
|
||||
@@ -19,8 +19,6 @@ class ProductsDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
@@ -6,7 +6,7 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\DataTables\CategoriesDataTable;
|
||||
use App\DataTables\Shop\CategoriesDataTable;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
@@ -40,7 +40,7 @@ class CategoryController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Categories::store($request);
|
||||
$ret = Categories::store($request->all());
|
||||
return redirect()->route('Shop.Admin.Categories.index');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,40 +5,26 @@ namespace App\Http\Controllers\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Categorys;
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\DataTables\Shop\CategoriesDataTable;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
|
||||
public function index(CategoriesDataTable $dataTable)
|
||||
{
|
||||
if ($request->ajax()) {
|
||||
return self::getDatatable($request);
|
||||
} else {
|
||||
$data = [];
|
||||
return view('Shop.Categories.list', $data);
|
||||
}
|
||||
}
|
||||
return $dataTable->render('Shop.Categories.list');
|
||||
}
|
||||
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Categories::getDatatable($request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Customer $customer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data = Categories::get($id);
|
||||
return view('Shop.Admin.Categories.view', $data);
|
||||
return view('Shop.Categories.view', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class Specie extends Model
|
||||
|
||||
public function Genre()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Botanic\Family');
|
||||
return $this->belongsTo('App\Models\Botanic\Genre');
|
||||
}
|
||||
|
||||
public function Varieties()
|
||||
|
||||
@@ -5,12 +5,20 @@ namespace App\Models\Shop;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Conner\Tagging\Taggable;
|
||||
|
||||
class Product extends Model
|
||||
class Article extends Model
|
||||
{
|
||||
use Categorizable;
|
||||
use Taggable;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_products';
|
||||
protected $table = 'shop_articles';
|
||||
|
||||
public function Family()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Family');
|
||||
}
|
||||
|
||||
public function Inventories()
|
||||
{
|
||||
@@ -19,17 +27,17 @@ class Product extends Model
|
||||
|
||||
public function Prices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ProductPrice');
|
||||
return $this->hasMany('App\Models\Shop\ArticlePrice');
|
||||
}
|
||||
|
||||
public function ProductAttributes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\ProductAttribute');
|
||||
return $this->hasMany('App\Models\Shop\ArticleAttribute');
|
||||
}
|
||||
|
||||
public function Categories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\CategoryProduct');
|
||||
return $this->hasMany('App\Models\Shop\ArticleCategory');
|
||||
}
|
||||
|
||||
public function InvoiceItems()
|
||||
@@ -4,15 +4,15 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductAttribute extends Model
|
||||
class ArticleAttribute extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function Product()
|
||||
public function Article()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Product');
|
||||
return $this->belongsTo('App\Models\Shop\Article');
|
||||
}
|
||||
}
|
||||
31
app/Models/Shop/ArticleCategory.php
Normal file
31
app/Models/Shop/ArticleCategory.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleCategory extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_categories';
|
||||
|
||||
public function Article()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function Category()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Category');
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, $id)
|
||||
{
|
||||
return $query->where('category_id', $id);
|
||||
}
|
||||
}
|
||||
19
app/Models/Shop/ArticleFamily.php
Normal file
19
app/Models/Shop/ArticleFamily.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleFamily extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_article_families';
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function Articles()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\Article');
|
||||
}
|
||||
}
|
||||
26
app/Models/Shop/ArticlePrice.php
Normal file
26
app/Models/Shop/ArticlePrice.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticlePrice extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function Article()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function ArticleAttribute()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\ArticleAttribute');
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,11 +5,12 @@ namespace App\Models\Shop;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Conner\Tagging\Taggable;
|
||||
|
||||
class Section extends Model
|
||||
class Category extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_sections';
|
||||
protected $table = 'shop_categories';
|
||||
|
||||
public function Category()
|
||||
{
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductPrice extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function Product()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Product');
|
||||
}
|
||||
|
||||
public function ProductAttribute()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\ProductAttribute');
|
||||
}
|
||||
|
||||
public function scopeByProduct($query, $id)
|
||||
{
|
||||
return $query->where('product_id', $id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductSection extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_product_sections';
|
||||
|
||||
public function Product()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Product');
|
||||
}
|
||||
|
||||
public function Section()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Product');
|
||||
}
|
||||
|
||||
public function scopeByProduct($query, $id)
|
||||
{
|
||||
return $query->where('product_id', $id);
|
||||
}
|
||||
|
||||
public function scopeBySection($query, $id)
|
||||
{
|
||||
return $query->where('section_id', $id);
|
||||
}
|
||||
}
|
||||
@@ -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