refactor datatables admin
This commit is contained in:
53
app/Datatables/Admin/Shop/TariffsDataTable.php
Normal file
53
app/Datatables/Admin/Shop/TariffsDataTable.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Admin\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Tariff;
|
||||
use App\Repositories\Shop\Tariffs;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class TariffsDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'tariffs';
|
||||
|
||||
public function query(Tariff $model)
|
||||
{
|
||||
$model = $model->with(['sale_channels'])->withCount(['price_lists', 'offers']);
|
||||
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('status', function (Tariff $tariff) {
|
||||
return Tariffs::getStatus($tariff['status_id']);
|
||||
})
|
||||
->editColumn('sale_channels2', function (Tariff $tariff) {
|
||||
$html = '';
|
||||
foreach ($tariff->sale_channels as $sale_channel) {
|
||||
$html .= $sale_channel->code.', ';
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->rawColumns(['sale_channels2', 'action']);
|
||||
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('status_id')->data('status')->title('status')->searchable(false)->orderable(false),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('sale_channels2')->title('Canaux de vente')->searchable(false)->orderable(false),
|
||||
Column::make('code')->title('Code'),
|
||||
Column::make('ref')->title('Référence'),
|
||||
Column::make('price_lists_count')->title('#Lst prix')->searchable(false)->orderable(false)->class('text-right'),
|
||||
Column::make('offers_count')->title('#Offres')->searchable(false)->orderable(false)->class('text-right'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user