diff --git a/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php index ea5fedfd5..986abba25 100644 --- a/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php @@ -52,15 +52,17 @@ public function prepareColumns(): void public function prepareActions(): void { $this->addAction([ + 'index' => 'edit', 'icon' => 'icon-edit', 'title' => trans('admin::app.settings.roles.index.datagrid.edit'), 'method' => 'GET', 'url' => function ($row) { - return route('admin.settings.types.edit', $row->id); + return route('admin.settings.types.update', $row->id); }, ]); $this->addAction([ + 'index' => 'delete', 'icon' => 'icon-delete', 'title' => trans('admin::app.settings.roles.index.datagrid.delete'), 'method' => 'DELETE', diff --git a/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php b/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php index 08a7009d4..ec84abfcf 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Setting/TypeController.php @@ -4,7 +4,6 @@ use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Event; -use Illuminate\Support\Facades\Validator; use Illuminate\View\View; use Webkul\Admin\DataGrids\Setting\TypeDataGrid; use Webkul\Admin\Http\Controllers\Controller; @@ -33,52 +32,41 @@ public function index(): View|JsonResponse /** * Store a newly created type in storage. - * - * @return \Illuminate\Http\Response */ - public function store() + public function store(): JsonResponse { - $validator = Validator::make(request()->all(), [ - 'name' => 'required|unique:lead_types,name', + $this->validate(request(), [ + 'name' => ['required', 'unique:lead_types,name'], ]); - if ($validator->fails()) { - session()->flash('error', trans('admin::app.settings.types.name-exists')); - - return redirect()->back(); - } - Event::dispatch('settings.type.create.before'); - $type = $this->typeRepository->create(request()->all()); + $type = $this->typeRepository->create(request()->only(['name'])); Event::dispatch('settings.type.create.after', $type); - session()->flash('success', trans('admin::app.settings.types.create-success')); - - return redirect()->route('admin.settings.types.index'); + return new JsonResponse([ + 'data' => $type, + 'message' => trans('admin::app.settings.types.index.create-success'), + ]); } /** * Show the form for editing the specified type. - * - * @param int $id - * @return \Illuminate\View\View */ - public function edit($id) + public function edit(int $id): View|JsonResponse { $type = $this->typeRepository->findOrFail($id); - return view('admin::settings.types.edit', compact('type')); + return new JsonResponse([ + 'data' => $type, + ]); } /** * Update the specified type in storage. - * - * @param int $id - * @return \Illuminate\Http\Response */ - public function update($id) + public function update(int $id): JsonResponse { $this->validate(request(), [ 'name' => 'required|unique:lead_types,name,'.$id, @@ -86,43 +74,37 @@ public function update($id) Event::dispatch('settings.type.update.before', $id); - $type = $this->typeRepository->update(request()->all(), $id); + $type = $this->typeRepository->update(request()->only(['name']), $id); Event::dispatch('settings.type.update.after', $type); - session()->flash('success', trans('admin::app.settings.types.update-success')); - - return redirect()->route('admin.settings.types.index'); + return new JsonResponse([ + 'data' => $type, + 'message' => trans('admin::app.settings.types.index.update-success'), + ]); } /** * Remove the specified type from storage. - * - * @param int $id - * @return \Illuminate\Http\Response */ - public function destroy($id) + public function destroy(int $id): JsonResponse { $type = $this->typeRepository->findOrFail($id); try { Event::dispatch('settings.type.delete.before', $id); - $this->typeRepository->delete($id); + $type->delete($id); Event::dispatch('settings.type.delete.after', $id); - return response()->json([ - 'message' => trans('admin::app.settings.types.delete-success'), + return new JsonResponse([ + 'message' => trans('admin::app.settings.types.index.delete-success'), ], 200); } catch (\Exception $exception) { - return response()->json([ - 'message' => trans('admin::app.settings.types.delete-failed'), + return new JsonResponse([ + 'message' => trans('admin::app.settings.types.index.delete-failed'), ], 400); } - - return response()->json([ - 'message' => trans('admin::app.settings.types.delete-failed'), - ], 400); } } diff --git a/packages/Webkul/Admin/src/Http/routes.php b/packages/Webkul/Admin/src/Http/routes.php index 9fb07b6cc..2dd12473a 100644 --- a/packages/Webkul/Admin/src/Http/routes.php +++ b/packages/Webkul/Admin/src/Http/routes.php @@ -352,18 +352,6 @@ Route::delete('{id}', 'SourceController@destroy')->name('admin.settings.sources.delete'); }); - // Lead Types Routes - Route::prefix('types')->group(function () { - Route::get('', 'TypeController@index')->name('admin.settings.types.index'); - - Route::post('create', 'TypeController@store')->name('admin.settings.types.store'); - - Route::get('edit/{id?}', 'TypeController@edit')->name('admin.settings.types.edit'); - - Route::put('edit/{id}', 'TypeController@update')->name('admin.settings.types.update'); - - Route::delete('{id}', 'TypeController@destroy')->name('admin.settings.types.delete'); - }); // Email Templates Routes Route::prefix('email-templates')->group(function () { diff --git a/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php b/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php index cb35a63ef..9d2f37768 100644 --- a/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php +++ b/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; use Webkul\Admin\Http\Middleware\Locale; +use Illuminate\Support\Facades\Route; class AdminServiceProvider extends ServiceProvider { @@ -18,6 +19,8 @@ public function boot(Router $router): void { include __DIR__.'/../Http/helpers.php'; + Route::middleware('web')->group(__DIR__.'/../Routes/web.php'); + $this->loadRoutesFrom(__DIR__.'/../Http/routes.php'); $this->loadMigrationsFrom(__DIR__.'/../Database/Migrations'); diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index d4dd5297e..676b856c2 100644 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -146,9 +146,11 @@ 'id' => 'ID', 'name' => 'Name', ], + 'edit' => [ 'title' => 'Edit Group', ], + 'create' => [ 'name' => 'Name', 'title' => 'Create Group', @@ -157,6 +159,79 @@ ], ], ], + + 'roles' => [ + 'index' => [ + 'create-btn' => 'Create Roles', + 'title' => 'Roles', + 'settings' => 'Settings', + 'datagrid' => [ + 'all' => 'All', + 'custom' => 'Custom', + 'delete' => 'Delete', + 'description' => 'Description', + 'edit' => 'Edit', + 'id' => 'ID', + 'name' => 'Name', + 'permission-type' => 'Permission Type', + ], + ], + + 'create' => [ + 'access-control' => 'Access Control', + 'all' => 'All', + 'back-btn' => 'Back', + 'custom' => 'Custom', + 'description' => 'Description', + 'general' => 'General', + 'name' => 'Name', + 'permissions' => 'Permissions', + 'save-btn' => 'Save Role', + 'title' => 'Create Role', + ], + + 'edit' => [ + 'access-control' => 'Access Control', + 'all' => 'All', + 'back-btn' => 'Back', + 'custom' => 'Custom', + 'description' => 'Description', + 'general' => 'General', + 'name' => 'Name', + 'permissions' => 'Permissions', + 'save-btn' => 'Save Role', + 'title' => 'Edit Role', + ], + ], + + 'types' => [ + 'index' => [ + 'create-btn' => 'Create Type', + 'title' => 'Types', + 'create-success' => 'Type created successfully.', + 'update-success' => 'Type updated successfully.', + 'delete-success' => 'Type deleted successfully.', + 'delete-failed' => 'Type can not be deleted.', + + 'datagrid' => [ + 'delete' => 'Delete', + 'description' => 'Description', + 'edit' => 'Edit', + 'id' => 'ID', + 'name' => 'Name', + ], + + 'create' => [ + 'name' => 'Name', + 'save-btn' => 'Save Type', + 'title' => 'Create Type', + ], + + 'edit' => [ + 'title' => 'Edit Type', + ], + ], + ], ], // ----------------------------------------------------------------Old version locale ---------------------------------- diff --git a/packages/Webkul/Admin/src/Resources/views/settings/types/index.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/types/index.blade.php index e5e773370..6d8283f1a 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/types/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/types/index.blade.php @@ -1,72 +1,260 @@ -@extends('admin::layouts.master') + + + @lang('admin::app.settings.types.index.title') + -@section('page_title') - {{ __('admin::app.settings.types.title') }} -@stop + +
+
+
+ + +
+ +
+ @lang('admin::app.settings.types.index.title') +
+
+ + +
+ + + +
-@section('content-wrapper') -
- -