Query Fixed

This commit is contained in:
devansh bawari 2020-12-30 16:35:41 +05:30
parent b6f1fed10d
commit 1e55a5c6b2
1 changed files with 15 additions and 8 deletions

View File

@ -2,12 +2,13 @@
namespace Webkul\Admin\DataGrids;
use Illuminate\Support\Facades\DB;
use Webkul\Core\Models\Channel;
use Webkul\Ui\DataGrid\DataGrid;
use Illuminate\Support\Facades\DB;
class SliderDataGrid extends DataGrid
{
protected $index = 'slider_id';
protected $index = 'id';
protected $sortOrder = 'desc';
@ -15,7 +16,11 @@ class SliderDataGrid extends DataGrid
protected $channel = 'all';
/** @var string[] contains the keys for which extra filters to render */
/**
* Contains the keys for which extra filters to render.
*
* @var string[]
**/
protected $extraFilters = [
'channels',
'locales',
@ -26,16 +31,18 @@ class SliderDataGrid extends DataGrid
parent::__construct();
$this->locale = request()->get('locale') ?? 'all';
$this->channel = request()->get('channel') ?? 'all';
$this->channel = request()->get('channel')
? Channel::find(request()->get('channel'))->code
: 'all';
}
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('sliders as sl')
->select('sl.id as slider_id', 'sl.title', 'sl.locale', 'ct.name', 'ch.code')
->select('sl.id', 'sl.title', 'sl.locale', 'ct.channel_id', 'ct.name', 'ch.code')
->leftJoin('channels as ch', 'sl.channel_id', '=', 'ch.id')
->leftJoin('channel_translations as ct', 'ch.id', '=', 'ct.channel_id')
->distinct();
->where('ct.locale', app()->getLocale());
if ($this->locale !== 'all') {
$queryBuilder->where('sl.locale', $this->locale);
@ -45,7 +52,7 @@ class SliderDataGrid extends DataGrid
$queryBuilder->where('ch.code', $this->channel);
}
$this->addFilter('slider_id', 'sl.id');
$this->addFilter('id', 'sl.id');
$this->addFilter('title', 'sl.title');
$this->addFilter('locale', 'sl.locale');
$this->addFilter('channel_name', 'ct.name');
@ -57,7 +64,7 @@ class SliderDataGrid extends DataGrid
public function addColumns()
{
$this->addColumn([
'index' => 'slider_id',
'index' => 'id',
'label' => trans('admin::app.datagrid.id'),
'type' => 'number',
'searchable' => false,