Build form for merchandise
This commit is contained in:
51
app/Datatables/Shop/MerchandisesDataTable.php
Normal file
51
app/Datatables/Shop/MerchandisesDataTable.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class MerchandisesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'merchandises';
|
||||
|
||||
public function query(Merchandise $model)
|
||||
{
|
||||
$model = $model::with(['image', 'tags'])->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 .= '<span class="btn btn-xs btn-secondary pb-2">' . $tag->slug . '</span> ';
|
||||
}
|
||||
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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
@section('content')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Merchandises.store', 'id' => 'form', 'autocomplete' => 'off', 'files' => true]) }}
|
||||
<input type="hidden" name="id" id="id" value="{{ $variety['id'] }}">
|
||||
<input type="hidden" name="id" id="id" value="{{ $merchandise['id'] }}">
|
||||
@include('Admin.Shop.Merchandises.form')
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@@ -3,39 +3,44 @@
|
||||
<div class="row mb-3">
|
||||
<div class="col-6">
|
||||
{{ Form::label('name', 'Nom') }}
|
||||
@include('components.form.input', ['name' => 'name', 'value' => $variety['name'] ?? null, 'required' => true])
|
||||
</div>
|
||||
<div class="col-6">
|
||||
{{ Form::label('genre', 'Espèce') }}
|
||||
@include('components.form.select', ['name' => 'specie_id', 'list' => $species, 'value' => $variety['specie_id'] ?? null, 'class' => 'select2 form-control', 'with_empty' => '', 'required' => false])
|
||||
@include('components.form.input', ['name' => 'name', 'value' => $merchandise['name'] ?? null, 'required' => true])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ Form::label('tags', 'Tags') }}
|
||||
@include('components.form.selects.select-tree', ['name' => 'tags[]', 'list' => $tags_list, 'values' => $variety['tags'] ?? null, 'class' => 'select2 form-control', 'multiple' => true])
|
||||
@include('components.form.selects.select-tree', [
|
||||
'name' => 'tags[]',
|
||||
'list' => $tags_list,
|
||||
'values' => $merchandise['tags'] ?? null,
|
||||
'class' => 'select2 form-control',
|
||||
'multiple' => true
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ Form::label('description', 'Description') }}
|
||||
@include('components.form.textarea', ['name' => 'description', 'value' => $variety['description'] ?? null, 'class' => 'editor', 'rows' => 5, 'required' => false])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
{{ Form::label('memo', 'Descriptif sachet') }}
|
||||
@include('components.form.textarea', ['name' => 'memo', 'value' => $variety['memo'] ?? null, 'class' => 'editor', 'rows' => 5, 'required' => false])
|
||||
@include('components.form.textarea', [
|
||||
'name' => 'description',
|
||||
'value' => $merchandise['description'] ?? null,
|
||||
'class' => 'editor',
|
||||
'rows' => 5,
|
||||
'required' => false,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
@include('components.uploader.widget', ['load_url' => route('Admin.Botanic.Varieties.getImages', ['id' => $variety['id'] ?? false]), 'delete_url' => route('Admin.Botanic.Varieties.deleteImage'), 'name' => 'images'])
|
||||
@include('components.uploader.widget', [
|
||||
'load_url' => route('Admin.Shop.Merchandises.getImages', ['id' => $merchandise['id'] ?? false]),
|
||||
'delete_url' => route('Admin.Botanic.Varieties.deleteImage'),
|
||||
'name' => 'images',
|
||||
])
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Botanic.varieties.title'),
|
||||
'subtitle' => __('Botanic.varieties.list'),
|
||||
'breadcrumb' => [__('Botanic.varieties.title')]
|
||||
'title' => __('Shop.merchandises.title'),
|
||||
'subtitle' => __('Shop.merchandises.list'),
|
||||
'breadcrumb' => [__('Shop.merchandises.title')]
|
||||
])
|
||||
|
||||
@section('content')
|
||||
@component('components.card')
|
||||
@include('components.datatable', ['route' => route('Admin.Botanic.Varieties.index'), 'model' => 'varieties'])
|
||||
@include('components.datatable', ['route' => route('Admin.Shop.Merchandises.index'), 'model' => 'merchandises'])
|
||||
@endcomponent
|
||||
@endsection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user