Add plus on products
This commit is contained in:
@@ -4,16 +4,16 @@ namespace App\Datatables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Repositories\Shop\Merchandises;
|
||||
use App\Models\Shop\Producer;
|
||||
use App\Repositories\Shop\Producers;
|
||||
|
||||
class MerchandisesDataTable extends DataTable
|
||||
class ProducersDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'merchandises';
|
||||
public $model_name = 'producers';
|
||||
|
||||
public function query(Merchandise $model)
|
||||
public function query(Producer $model)
|
||||
{
|
||||
$model = $model::with(['image', 'tags'])->withCount(['Articles', 'tags', 'images']);
|
||||
$model = $model::with(['image', 'tags'])->withCount(['Merchandises', 'tags', 'images']);
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ class MerchandisesDataTable extends DataTable
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('thumb', function (Merchandise $merchandise) {
|
||||
return Merchandises::getThumb($merchandise->image);
|
||||
->editColumn('thumb', function (Producer $producer) {
|
||||
return $producer->image ? Producers::getThumb($producer->image) : '';
|
||||
})
|
||||
->editColumn('tags2', function (Merchandise $merchandise) {
|
||||
->editColumn('tags2', function (Producer $producer) {
|
||||
$html = '';
|
||||
foreach ($merchandise->tags as $tag) {
|
||||
foreach ($producer->tags as $tag) {
|
||||
$html .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
|
||||
}
|
||||
return $html;
|
||||
@@ -42,7 +42,7 @@ class MerchandisesDataTable extends DataTable
|
||||
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('tags2')->title('Tags')->searchable(false)->orderable(false),
|
||||
Column::make('articles_count')->title('#Art')->class('text-right')->searchable(false),
|
||||
Column::make('merchandises_count')->title('#Mar')->class('text-right')->searchable(false),
|
||||
Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false),
|
||||
Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false),
|
||||
$this->makeColumnButtons(),
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Repositories\Shop\Merchandises;
|
||||
use App\Repositories\Shop\Producers;
|
||||
use App\Repositories\Shop\TagGroups;
|
||||
use App\Datatables\Shop\MerchandisesDataTable;
|
||||
|
||||
@@ -19,6 +20,7 @@ class MerchandiseController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data['producers_list'] = Producers::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Admin.Shop.Merchandises.create', $data);
|
||||
}
|
||||
@@ -38,6 +40,7 @@ class MerchandiseController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data['merchandise'] = Merchandises::getFull($id);
|
||||
$data['producers_list'] = Producers::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
return view('Admin.Shop.Merchandises.edit', $data);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class LoginController extends Controller
|
||||
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('Shop.auth.login', $data ?? []);
|
||||
return view('auth.login', $data ?? []);
|
||||
}
|
||||
|
||||
public function authenticated(Request $request, $user)
|
||||
|
||||
@@ -14,6 +14,10 @@ class Merchandises
|
||||
|
||||
$menu->addTo('merchandises', __('Marchandises'), [
|
||||
'route' => 'Admin.Shop.Merchandises.index',
|
||||
])->activeIfRoute(['Admin.Shop.Merchandises.*'])->order(1);
|
||||
])->activeIfRoute(['Admin.Shop.Merchandises.*'])->order(1);
|
||||
|
||||
$menu->addTo('merchandises', __('Producteurs'), [
|
||||
'route' => 'Admin.Shop.Producers.index',
|
||||
])->activeIfRoute(['Admin.Shop.Producers.*'])->order(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ use Rinvex\Tags\Traits\Taggable;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
|
||||
use App\Traits\Model\Imageable;
|
||||
use App\Models\Shop\Tag;
|
||||
use App\Models\Shop\Article;
|
||||
|
||||
class Specie extends Model implements HasMedia
|
||||
{
|
||||
@@ -20,7 +22,7 @@ class Specie extends Model implements HasMedia
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
public function Genre()
|
||||
@@ -35,7 +37,7 @@ class Specie extends Model implements HasMedia
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
return $this->morphMany('App\Models\Shop\Article', 'product');
|
||||
return $this->morphMany(Article::class, 'product');
|
||||
}
|
||||
|
||||
public function scopeByName($query, $name)
|
||||
|
||||
@@ -12,6 +12,9 @@ use Wildside\Userstamps\Userstamps;
|
||||
|
||||
use App\Traits\Model\Imageable;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Tag;
|
||||
|
||||
class Variety extends Model implements HasMedia
|
||||
{
|
||||
use Imageable, PowerJoins, SoftDeletes, Taggable, UserStamps;
|
||||
@@ -21,16 +24,16 @@ class Variety extends Model implements HasMedia
|
||||
|
||||
public function Specie()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Botanic\Specie');
|
||||
return $this->belongsTo(Specie::class);
|
||||
}
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
return $this->morphMany('App\Models\Shop\Article', 'product');
|
||||
return $this->morphMany(Article::class, 'product');
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Shop\Tag', 'taggable');
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,14 @@ class Producer extends Model implements HasMedia
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_producers';
|
||||
|
||||
public function Articles()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function Merchandises()
|
||||
{
|
||||
return $this->morphMany(Article::class, 'product');
|
||||
return $this->hasMany(Merchandise::class);
|
||||
}
|
||||
|
||||
public function tags()
|
||||
|
||||
95
app/Repositories/Shop/Producers.php
Normal file
95
app/Repositories/Shop/Producers.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Models\Shop\Producer;
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
class Producers
|
||||
{
|
||||
use Imageable;
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Producer::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getTags($id)
|
||||
{
|
||||
return self::get($id)->tags;
|
||||
}
|
||||
|
||||
public static function storeTags($variety, $tags)
|
||||
{
|
||||
return Tag::storeTags($variety, $tags);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Producer::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Producer::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Producer::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$producer = self::get($id);
|
||||
$data = $producer->toArray();
|
||||
$data['tags'] = self::getTagsByProducer($producer);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getTagsByProducer($producer)
|
||||
{
|
||||
return Tag::getTagsByModel($producer);
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = $data['images'] ?? false;
|
||||
$tags = $data['tags'] ?? false;
|
||||
unset($data['images']);
|
||||
unset($data['tags']);
|
||||
$producer = self::store($data);
|
||||
self::storeImages($producer, $images);
|
||||
self::storeTags($producer, $tags);
|
||||
return $producer;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Producer::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Producer::destroy($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user