Merge pull request #5092 from devansh-webkul/slider-issue
Slider issue fixed on DB prefix #5091
This commit is contained in:
commit
3a433b837f
|
|
@ -2,30 +2,55 @@
|
|||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Set index columns, ex: id.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $index = 'id';
|
||||
|
||||
/**
|
||||
* Default sort order of datagrid.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $sortOrder = 'desc';
|
||||
|
||||
/**
|
||||
* Locale.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $locale = 'all';
|
||||
|
||||
/**
|
||||
* Channel.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $channel = 'all';
|
||||
|
||||
/**
|
||||
* Contains the keys for which extra filters to render.
|
||||
*
|
||||
* @var string[]
|
||||
**/
|
||||
*/
|
||||
protected $extraFilters = [
|
||||
'channels',
|
||||
'locales',
|
||||
];
|
||||
|
||||
/**
|
||||
* Create datagrid instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
|
@ -43,16 +68,23 @@ class SliderDataGrid extends DataGrid
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare query builder.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
$dbPrefix = DB::getTablePrefix();
|
||||
|
||||
$queryBuilder = DB::table('sliders as sl')
|
||||
->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')
|
||||
->where('ct.locale', app()->getLocale());
|
||||
->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')
|
||||
->where('ct.locale', app()->getLocale());
|
||||
|
||||
if ($this->locale !== 'all') {
|
||||
$queryBuilder->whereRaw("find_in_set(?, sl.locale)", [$this->locale]);
|
||||
$queryBuilder->whereRaw("find_in_set(?, {$dbPrefix}sl.locale)", [$this->locale]);
|
||||
}
|
||||
|
||||
if ($this->channel !== 'all') {
|
||||
|
|
@ -68,6 +100,11 @@ class SliderDataGrid extends DataGrid
|
|||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addColumns()
|
||||
{
|
||||
$this->addColumn([
|
||||
|
|
@ -107,6 +144,11 @@ class SliderDataGrid extends DataGrid
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare actions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareActions()
|
||||
{
|
||||
$this->addAction([
|
||||
|
|
@ -123,4 +165,4 @@ class SliderDataGrid extends DataGrid
|
|||
'icon' => 'icon trash-icon',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,20 +7,22 @@ use Webkul\Core\Repositories\SliderRepository;
|
|||
class SliderController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* SliderRepository
|
||||
* Slider repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Repositories\SliderRepository
|
||||
*/
|
||||
protected $sliderRepository;
|
||||
|
||||
/**
|
||||
* Channels.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $channels;
|
||||
|
|
@ -61,7 +63,7 @@ class SliderController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates the new sider item.
|
||||
* Creates the new slider item.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
|
@ -75,6 +77,7 @@ class SliderController extends Controller
|
|||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['expired_at'] = $data['expired_at'] ?: null;
|
||||
|
||||
if (isset($data['locale'])) {
|
||||
|
|
@ -120,13 +123,14 @@ class SliderController extends Controller
|
|||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['expired_at'] = $data['expired_at'] ?: null;
|
||||
|
||||
if (isset($data['locale'])) {
|
||||
$data['locale'] = implode(',', $data['locale']);
|
||||
}
|
||||
|
||||
if ( is_null(request()->image)) {
|
||||
if (is_null(request()->image)) {
|
||||
session()->flash('error', trans('admin::app.settings.sliders.update-fail'));
|
||||
|
||||
return redirect()->back();
|
||||
|
|
@ -144,14 +148,14 @@ class SliderController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete a slider item and preserve the last one from deleting
|
||||
* Delete the slider item and preserve the last one from deleting.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$slider = $this->sliderRepository->findOrFail($id);
|
||||
$this->sliderRepository->findOrFail($id);
|
||||
|
||||
try {
|
||||
$this->sliderRepository->delete($id);
|
||||
|
|
@ -159,10 +163,10 @@ class SliderController extends Controller
|
|||
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Slider']));
|
||||
|
||||
return response()->json(['message' => true], 200);
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Slider']));
|
||||
}
|
||||
|
||||
return response()->json(['message' => false], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue