eloquent($query) ->filter(function ($query) { $search = request()->get('search'); if ($search['value'] !== "") { $query->where('name', 'like', "%" . $search['value'] . "%") ->orWhere('address', 'like', "%" . $search['value'] . "%") ->orWhere('phone', 'like', "%" . $search['value'] . "%") ->orWhere('website', 'like', "%" . $search['value'] . "%") ->orWhere('email', 'like', "%" . $search['value'] . "%") ->orWhere('npwp', 'like', "%" . $search['value'] . "%") ->orWhere('company_type', 'like', "%" . $search['value'] . "%"); } }) ->addIndexColumn() ->addColumn('action', function ($model) { return view('company::_action', compact('model')); }); } /** * Get query source of dataTable. * * @param \Modules\Company\Entities\Company $model * * @return \Illuminate\Database\Eloquent\Builder */ public function query(Company $model) { return $model->newQuery(); } /** * Optional method if you want to use html builder. * * @return \Yajra\DataTables\Html\Builder */ public function html() { return $this->builder() ->setTableId('company-table') ->columns($this->getColumns()) ->minifiedAjax() ->orderBy(1, 'asc') ->stateSave(false) ->responsive() ->autoWidth(false) ->parameters([ 'scrollX' => true, 'drawCallback' => 'function() { KTMenu.createInstances(); }', ]) ->addTableClass('align-middle table-row-dashed fs-6 gy-5'); } /** * Get columns. * * @return array */ protected function getColumns() { return [ Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), Column::make('name')->title(__('Name')), Column::make('company_type')->title(__('Company Type')), Column::make('npwp')->title(__('NPWP')), Column::make('address')->title(__('Address')), Column::make('email')->className('none'), Column::make('phone')->title(__('Phone'))->className('none'), Column::make('website')->title(__('Website'))->className('none'), Column::computed('action') ->exportable(false) ->printable(false) ->addClass('text-center') ->responsivePriority(-1), ]; } /** * Get filename for export. * * @return string */ protected function filename() : string { return 'Company_' . date('YmdHis'); } }