Add varieties
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Console\Commands;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Shop\Family;
|
||||
use App\Models\Shop\Genre;
|
||||
use App\Models\Shop\Specie;
|
||||
use App\Models\Shop\Variety;
|
||||
|
||||
class migrate extends Command
|
||||
{
|
||||
@@ -39,6 +41,45 @@ class migrate extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$varieties = Variety::all();
|
||||
foreach ($varieties as $variety) {
|
||||
$specie_name = $variety->specie;
|
||||
dump($specie_name);
|
||||
if (!empty($specie_name)) {
|
||||
$specie = Specie::byName($specie_name)->first();
|
||||
if (isset($specie->name))
|
||||
{
|
||||
dump($specie->name);
|
||||
$variety->specie_id = $specie->id;
|
||||
$variety->save();
|
||||
} else {
|
||||
dump("non trouvé");
|
||||
}
|
||||
} else {
|
||||
dump("Aucune espèce");
|
||||
}
|
||||
}
|
||||
/*
|
||||
$species = Specie::all();
|
||||
foreach ($species as $specie) {
|
||||
$genre_name = $specie->genre;
|
||||
dump($genre_name);
|
||||
if (!empty($genre_name)) {
|
||||
$genre = Genre::byName($genre_name)->first();
|
||||
if (isset($genre->name))
|
||||
{
|
||||
dump($genre->name);
|
||||
$specie->genre_id = $genre->id;
|
||||
$specie->save();
|
||||
} else {
|
||||
dump("non trouvé");
|
||||
}
|
||||
} else {
|
||||
dump("Aucun genre");
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
$genres = Genre::all();
|
||||
foreach ($genres as $genre) {
|
||||
$family_name = $genre->family;
|
||||
@@ -57,5 +98,6 @@ class migrate extends Command
|
||||
dump("Aucune famille");
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,21 @@ class FamiliesDataTable extends DataTable
|
||||
|
||||
public function query(Family $model)
|
||||
{
|
||||
$model = $model::withCount('genres');
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::make('genres_count')->title('Nb genres'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
->searchable(false)
|
||||
->width(120)
|
||||
->addClass('text-center'),
|
||||
];
|
||||
|
||||
@@ -12,15 +12,18 @@ class GenresDataTable extends DataTable
|
||||
|
||||
public function query(Genre $model)
|
||||
{
|
||||
$model = $model::with('family')->withCount('species');
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::make('family.name'),
|
||||
Column::make('species_count')->title('Nb Espèces'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
|
||||
@@ -29,11 +29,17 @@ class ParentDataTable extends DataTable
|
||||
* @return \Yajra\DataTables\DataTableAbstract
|
||||
*/
|
||||
public function addButtons($datatables)
|
||||
{
|
||||
$buttons = self::getHtmlButtons();
|
||||
return $datatables->addColumn('action', $buttons);
|
||||
}
|
||||
|
||||
public function getHtmlButtons()
|
||||
{
|
||||
$buttons = '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
|
||||
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-edit"></i></button>';
|
||||
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
|
||||
return $datatables->addColumn('action', $buttons);
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
32
app/Datatables/VarietiesDataTable.php
Normal file
32
app/Datatables/VarietiesDataTable.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\DataTables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Variety;
|
||||
|
||||
class VarietiesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'Varieties';
|
||||
|
||||
public function query(Variety $model)
|
||||
{
|
||||
$model = $model::with('specie');
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('specie_name'),
|
||||
Column::make('name'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
->width(120)
|
||||
->addClass('text-center'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Genres;
|
||||
use App\Repositories\Shop\Families;
|
||||
use App\DataTables\GenresDataTable;
|
||||
|
||||
class GenreController extends Controller
|
||||
@@ -39,7 +40,8 @@ class GenreController extends Controller
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['genre'] = Genres::get($id);
|
||||
$data = Genres::get($id);
|
||||
$data['families'] = Families::getOptions();
|
||||
return view('Shop.Admin.Genres.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Species;
|
||||
use App\Repositories\Shop\Genres;
|
||||
use App\DataTables\SpeciesDataTable;
|
||||
|
||||
class SpecieController extends Controller
|
||||
@@ -39,7 +40,8 @@ class SpecieController extends Controller
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['specie'] = Species::get($id);
|
||||
$data = Species::get($id);
|
||||
$data['genres'] = Genres::getOptions();
|
||||
return view('Shop.Admin.Species.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
53
app/Http/Controllers/Shop/Admin/VarietyController.php
Normal file
53
app/Http/Controllers/Shop/Admin/VarietyController.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Varieties;
|
||||
use App\Repositories\Shop\Species;
|
||||
use App\DataTables\VarietiesDataTable;
|
||||
|
||||
class VarietyController extends Controller
|
||||
{
|
||||
public function index(VarietiesDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Shop.Admin.Varieties.list');
|
||||
}
|
||||
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Varieties::getDatatable($request->all());
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('Shop.Admin.Varieties.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Varieties::store($request);
|
||||
return redirect()->route('Shop.Admin.Varieties.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data = Varieties::get($id);
|
||||
return view('Shop.Admin.Varieties.view', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Varieties::get($id);
|
||||
$data['species'] = Species::getOptions();
|
||||
return view('Shop.Admin.Varieties.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Varieties::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,15 +20,17 @@ class Shop
|
||||
->activeIfRoute(['Shop.Admin.Genres.index'])->order(2);
|
||||
$menu->addTo('shop', 'Espèces', [ 'route' => 'Shop.Admin.Species.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Species.index'])->order(3);
|
||||
$menu->addTo('shop', 'Variétés', [ 'route' => 'Shop.Admin.Varieties.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Varieties.index'])->order(4);
|
||||
|
||||
$menu->addTo('shop', 'Categories', [ 'route' => 'Shop.Admin.Sections.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Sections.index'])->order(4);
|
||||
->activeIfRoute(['Shop.Admin.Sections.index'])->order(5);
|
||||
$menu->addTo('shop', 'Produits', [ 'route' => 'Shop.Admin.Products.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Products.index'])->order(5);
|
||||
->activeIfRoute(['Shop.Admin.Products.index'])->order(6);
|
||||
$menu->addTo('shop', 'Commandes', [ 'route' => 'Shop.Admin.Orders.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Orders.index'])->order(6);
|
||||
->activeIfRoute(['Shop.Admin.Orders.index'])->order(7);
|
||||
$menu->addTo('shop', 'Factures', [ 'route' => 'Shop.Admin.Invoices.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Invoices.index'])->order(7);
|
||||
->activeIfRoute(['Shop.Admin.Invoices.index'])->order(8);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ class Genre extends Model
|
||||
return $this->belongsTo('App\Models\Shop\Family');
|
||||
}
|
||||
|
||||
public function species()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\Specie');
|
||||
}
|
||||
|
||||
public function scopeByName($query,$name)
|
||||
{
|
||||
return $query->where('name', $name);
|
||||
|
||||
@@ -13,4 +13,15 @@ class Specie extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Family');
|
||||
}
|
||||
|
||||
public function Varieties()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\Variety');
|
||||
}
|
||||
|
||||
public function scopeByName($query,$name)
|
||||
{
|
||||
return $query->where('name', $name);
|
||||
}
|
||||
|
||||
}
|
||||
16
app/Models/Shop/Variety.php
Normal file
16
app/Models/Shop/Variety.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Variety extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_product_varieties';
|
||||
|
||||
public function Specie()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Specie');
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,11 @@ class Families
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Family::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Family::orderBy('name','asc')->get();
|
||||
|
||||
@@ -19,6 +19,11 @@ class Genres
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Family::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Genre::orderBy('name','asc')->get();
|
||||
|
||||
Reference in New Issue
Block a user