From 08caac23fa3a28afb82a37f63ea931385424bef3 Mon Sep 17 00:00:00 2001 From: Shivendra Date: Fri, 19 Jul 2024 09:47:34 +0530 Subject: [PATCH] Update type datagrid --- .../src/DataGrids/Setting/TypeDataGrid.php | 42 +++++++++---------- .../Controllers/Setting/TypeController.php | 9 ++-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php index 29c4651e4..d6a05ede2 100644 --- a/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php @@ -2,17 +2,16 @@ namespace Webkul\Admin\DataGrids\Setting; -use Webkul\UI\DataGrid\DataGrid; use Illuminate\Support\Facades\DB; +use Webkul\DataGrid\DataGrid; +use Illuminate\Database\Query\Builder; class TypeDataGrid extends DataGrid { /** * Prepare query builder. - * - * @return void */ - public function prepareQueryBuilder() + public function prepareQueryBuilder(): Builder { $queryBuilder = DB::table('lead_types') ->addSelect( @@ -22,51 +21,52 @@ public function prepareQueryBuilder() $this->addFilter('id', 'lead_types.id'); - $this->setQueryBuilder($queryBuilder); + return $queryBuilder; } /** * Add columns. - * - * @return void */ - public function addColumns() + public function prepareColumns(): void { $this->addColumn([ 'index' => 'id', 'label' => trans('admin::app.datagrid.id'), 'type' => 'string', - 'sortable' => true, + 'filterable' => true, + 'sortable' => true, ]); $this->addColumn([ 'index' => 'name', 'label' => trans('admin::app.datagrid.name'), 'type' => 'string', - 'sortable' => true, + 'filterable' => true, + 'sortable' => true, ]); } /** * Prepare actions. - * - * @return void */ - public function prepareActions() + public function prepareActions(): void { $this->addAction([ - 'title' => trans('ui::app.datagrid.edit'), + 'icon' => 'icon-edit', + 'title' => trans('admin::app.settings.roles.index.datagrid.edit'), 'method' => 'GET', - 'route' => 'admin.settings.types.edit', - 'icon' => 'pencil-icon', + 'url' => function ($row) { + return route('admin.settings.types.edit', $row->id); + }, ]); $this->addAction([ - 'title' => trans('ui::app.datagrid.delete'), - 'method' => 'DELETE', - 'route' => 'admin.settings.types.delete', - 'confirm_text' => trans('ui::app.datagrid.mass-action.delete', ['resource' => 'type']), - 'icon' => 'trash-icon', + 'icon' => 'icon-delete', + 'title' => trans('admin::app.settings.roles.index.datagrid.delete'), + 'method' => 'DELETE', + 'url' => function ($row) { + return route('admin.settings.types.delete', $row->id); + }, ]); } } diff --git a/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php b/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php index 64be27bf5..5d13a11b5 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php @@ -3,9 +3,12 @@ namespace Webkul\Admin\Http\Controllers\Setting; use Illuminate\Support\Facades\Event; +use Illuminate\Http\JsonResponse; +use Illuminate\View\View; use Illuminate\Support\Facades\Validator; use Webkul\Admin\Http\Controllers\Controller; use Webkul\Lead\Repositories\TypeRepository; +use Webkul\Admin\DataGrids\Setting\TypeDataGrid; class TypeController extends Controller { @@ -20,13 +23,11 @@ public function __construct(protected TypeRepository $typeRepository) /** * Display a listing of the type. - * - * @return \Illuminate\View\View */ - public function index() + public function index(): View|JsonResponse { if (request()->ajax()) { - return app(\Webkul\Admin\DataGrids\Setting\TypeDataGrid::class)->toJson(); + return datagrid(TypeDataGrid::class)->process(); } return view('admin::settings.types.index');