From 193f5cf4ada6e60c1b85bcba5d8cf28511599f9a Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Thu, 24 Mar 2022 10:08:23 +0100 Subject: [PATCH] Add toggle for homepage --- app/Datatables/Shop/CategoriesDataTable.php | 21 +++++++++++++++---- .../Admin/Shop/CategoryController.php | 6 ++++++ app/Repositories/Shop/Categories.php | 5 +++++ .../Admin/Shop/Categories/list.blade.php | 3 ++- routes/Admin/Shop/Articles.php | 4 ++-- routes/Admin/Shop/Categories.php | 1 + 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/Datatables/Shop/CategoriesDataTable.php b/app/Datatables/Shop/CategoriesDataTable.php index df985a9a..6b46237a 100644 --- a/app/Datatables/Shop/CategoriesDataTable.php +++ b/app/Datatables/Shop/CategoriesDataTable.php @@ -26,10 +26,22 @@ class CategoriesDataTable extends DataTable return view("components.form.toggle", [ 'name' => 'visible', 'value' => $category->visible, - 'on' => __('visible'), - 'off' => __('invisible'), + 'on' => __('oui'), + 'off' => __('non'), 'meta' => 'data-id=' . $category->id, - 'size' => 'xs', + 'size' => 'sm', + 'class' => 'visible', + ]); + }) + ->editColumn('homepage', function (Category $category) { + return view("components.form.toggle", [ + 'name' => 'homepage', + 'value' => $category->homepage, + 'on' => __('oui'), + 'off' => __('non'), + 'meta' => 'data-id=' . $category->id, + 'size' => 'sm', + 'class' => 'homepage', ]); }) ->editColumn('articles_tagged_count', function (Category $category) { @@ -47,7 +59,8 @@ class CategoriesDataTable extends DataTable protected function getColumns() { return [ - Column::make('visible')->title('visible')->width(60)->title(''), + Column::make('visible')->title('visible')->width(60), + Column::make('homepage')->title('homepage')->width(60), Column::make('name')->title('Nom'), Column::make('articles_count')->title('#Art')->class('text-right')->orderable(false)->searchable(false)->width(60), Column::make('tags_count')->title('#Tags')->class('text-right')->searchable(false)->width(60), diff --git a/app/Http/Controllers/Admin/Shop/CategoryController.php b/app/Http/Controllers/Admin/Shop/CategoryController.php index bcecf84e..502a6191 100644 --- a/app/Http/Controllers/Admin/Shop/CategoryController.php +++ b/app/Http/Controllers/Admin/Shop/CategoryController.php @@ -78,4 +78,10 @@ class CategoryController extends Controller return response()->json(['error' => 0]); } + public function toggleHomepage(Request $request) + { + $data = Categories::toggleHomepage($request->input('id'), ($request->input('homepage') == 'true') ? 1 : 0); + return response()->json(['error' => 0]); + } + } diff --git a/app/Repositories/Shop/Categories.php b/app/Repositories/Shop/Categories.php index 1dd83867..ad380af1 100644 --- a/app/Repositories/Shop/Categories.php +++ b/app/Repositories/Shop/Categories.php @@ -148,6 +148,11 @@ class Categories return self::update(['visible' => $visible], $id); } + public static function toggleHomepage($id, $homepage) + { + return self::update(['homepage' => $homepage], $id); + } + public static function getRoot() { return app('rinvex.categories.category')->find(1); diff --git a/resources/views/Admin/Shop/Categories/list.blade.php b/resources/views/Admin/Shop/Categories/list.blade.php index 297e2e10..2c14ea53 100644 --- a/resources/views/Admin/Shop/Categories/list.blade.php +++ b/resources/views/Admin/Shop/Categories/list.blade.php @@ -27,7 +27,8 @@ @push('js')