eloquent($query)->with('category')
->addColumn('action', function ($data) {
return view('product::products.partials.actions', compact('data'));
})
->addColumn('product_image', function ($data) {
$url = $data->getFirstMediaUrl();
return '
';
})
->rawColumns(['product_image']);
}
/**
* Get query source of dataTable.
*
* @param \Modules\Product\Entities\Product $model
* @return \Illuminate\Database\Eloquent\Builder
*/
public function query(Product $model)
{
return $model->newQuery()->with('category');
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->setTableId('product-table')
->columns($this->getColumns())
->minifiedAjax()
->dom("<'row'<'col-md-3'l><'col-md-5 mb-2'B><'col-md-4'f>> .
'tr' .
<'row'<'col-md-5'i><'col-md-7 mt-2'p>>")
->orderBy(0)
->buttons(
Button::make('excel')
->text(' Excel'),
Button::make('print')
->text(' Print'),
Button::make('reset')
->text(' Reset'),
Button::make('reload')
->text(' Reload')
);
}
/**
* Get columns.
*
* @return array
*/
protected function getColumns()
{
return [
Column::computed('product_image')
->title('Image')
->addClass('text-center')
->addClass('align-middle'),
Column::make('product_name')
->title('Name')
->addClass('text-center')
->addClass('align-middle'),
Column::make('product_code')
->title('Code')
->addClass('text-center')
->addClass('align-middle'),
Column::make('product_price')
->title('Price')
->addClass('text-center')
->addClass('align-middle'),
Column::make('product_quantity')
->title('Quantity')
->addClass('text-center')
->addClass('align-middle'),
Column::make('category.category_name')
->title('Category')
->addClass('text-center')
->addClass('align-middle'),
Column::computed('action')
->exportable(false)
->printable(false)
->addClass('text-center')
->addClass('align-middle'),
];
}
/**
* Get filename for export.
*
* @return string
*/
protected function filename()
{
return 'Product_' . date('YmdHis');
}
}