diff --git a/app/Datatables/Shop/MerchandisesDataTable.php b/app/Datatables/Shop/MerchandisesDataTable.php new file mode 100644 index 00000000..3a0b4df2 --- /dev/null +++ b/app/Datatables/Shop/MerchandisesDataTable.php @@ -0,0 +1,51 @@ +withCount(['Articles', 'tags', 'images']); + return $this->buildQuery($model); + } + + + public function modifier($datatables) + { + $datatables + ->editColumn('thumb', function (Merchandise $merchandise) { + return Merchandises::getThumb($merchandise->image); + }) + ->editColumn('tags2', function (Merchandise $merchandise) { + $html = ''; + foreach ($merchandise->tags as $tag) { + $html .= '' . $tag->slug . ' '; + } + return $html; + }) + ->rawColumns(['thumb', 'tags2', 'action']); + return parent::modifier($datatables); + } + + + protected function getColumns() + { + return [ + 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('tags_count')->title('#Tag')->class('text-right')->searchable(false), + Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false), + $this->makeColumnButtons(), + ]; + } +} diff --git a/app/Models/Shop/Merchandise.php b/app/Models/Shop/Merchandise.php index fe84c854..5f9f61b0 100644 --- a/app/Models/Shop/Merchandise.php +++ b/app/Models/Shop/Merchandise.php @@ -3,12 +3,18 @@ namespace App\Models\Shop; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; +use Spatie\MediaLibrary\HasMedia; use Rinvex\Tags\Traits\Taggable; +use Kirschbaum\PowerJoins\PowerJoins; +use Wildside\Userstamps\Userstamps; -class Merchandise extends Model +use App\Traits\Model\Imageable; + +class Merchandise extends Model implements HasMedia { - use Taggable; + use Imageable, PowerJoins, SoftDeletes, Taggable, UserStamps; protected $guarded = ['id']; protected $table = 'shop_merchandises'; @@ -17,4 +23,9 @@ class Merchandise extends Model { return $this->morphMany(Article::class, 'product'); } + + public function tags() + { + return $this->morphToMany('App\Models\Shop\Tag', 'taggable'); + } } diff --git a/resources/views/Admin/Shop/Merchandises/edit.blade.php b/resources/views/Admin/Shop/Merchandises/edit.blade.php index fcb94a29..f27012c1 100644 --- a/resources/views/Admin/Shop/Merchandises/edit.blade.php +++ b/resources/views/Admin/Shop/Merchandises/edit.blade.php @@ -6,7 +6,7 @@ @section('content') {{ Form::open(['route' => 'Admin.Shop.Merchandises.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }} - + @include('Admin.Shop.Merchandises.form') @endsection diff --git a/resources/views/Admin/Shop/Merchandises/form.blade.php b/resources/views/Admin/Shop/Merchandises/form.blade.php index 562ec17a..92005db3 100644 --- a/resources/views/Admin/Shop/Merchandises/form.blade.php +++ b/resources/views/Admin/Shop/Merchandises/form.blade.php @@ -3,39 +3,44 @@