From 8a2b72ca5d1f4a38404e3af69f6af16a617fa4dd Mon Sep 17 00:00:00 2001 From: Amanmyrat Date: Tue, 6 Dec 2022 11:15:35 +0500 Subject: [PATCH] added orderable to contacts --- .../Admin/ContactCrudController.php | 10 +++++ ...124321_add_reorder_to_categories_table.php | 2 +- ...022_12_05_113105_create_contacts_table.php | 4 -- ...6_124321_add_reorder_to_contacts_table.php | 40 +++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2022_12_6_124321_add_reorder_to_contacts_table.php diff --git a/app/Http/Controllers/Admin/ContactCrudController.php b/app/Http/Controllers/Admin/ContactCrudController.php index 2c8f422..1af3568 100644 --- a/app/Http/Controllers/Admin/ContactCrudController.php +++ b/app/Http/Controllers/Admin/ContactCrudController.php @@ -18,6 +18,7 @@ class ContactCrudController extends CrudController use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation; + use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation; /** * Configure the CrudPanel object. Apply settings to all operations. @@ -84,4 +85,13 @@ class ContactCrudController extends CrudController { $this->setupCreateOperation(); } + + protected function setupReorderOperation() + { + // define which model attribute will be shown on draggable elements + $this->crud->set('reorder.label', 'title'); + // define how deep the admin is allowed to nest the items + // for infinite levels, set it to 0 + $this->crud->set('reorder.max_level', 1); + } } diff --git a/database/migrations/2022_11_20_124321_add_reorder_to_categories_table.php b/database/migrations/2022_11_20_124321_add_reorder_to_categories_table.php index d7c522e..f6cf19a 100644 --- a/database/migrations/2022_11_20_124321_add_reorder_to_categories_table.php +++ b/database/migrations/2022_11_20_124321_add_reorder_to_categories_table.php @@ -28,7 +28,7 @@ class AddReorderToCategoriesTable extends Migration */ public function down() { - Schema::table('exports', function (Blueprint $table) { + Schema::table('categories', function (Blueprint $table) { $table->dropColumn('parent_id'); $table->dropColumn('lft'); $table->dropColumn('rgt'); diff --git a/database/migrations/2022_12_05_113105_create_contacts_table.php b/database/migrations/2022_12_05_113105_create_contacts_table.php index 56b15a0..035c9d5 100644 --- a/database/migrations/2022_12_05_113105_create_contacts_table.php +++ b/database/migrations/2022_12_05_113105_create_contacts_table.php @@ -17,10 +17,6 @@ class CreateContactsTable extends Migration $table->id(); $table->text('name'); $table->longText('contacts'); - $table->integer('parent_id')->default(0)->nullable(); - $table->integer('lft')->default(0); - $table->integer('rgt')->default(0); - $table->integer('depth')->default(0); $table->timestamps(); }); } diff --git a/database/migrations/2022_12_6_124321_add_reorder_to_contacts_table.php b/database/migrations/2022_12_6_124321_add_reorder_to_contacts_table.php new file mode 100644 index 0000000..026f7af --- /dev/null +++ b/database/migrations/2022_12_6_124321_add_reorder_to_contacts_table.php @@ -0,0 +1,40 @@ +after('contacts', function ($table) { + $table->integer('parent_id')->default(0)->nullable(); + $table->integer('lft')->default(0); + $table->integer('rgt')->default(0); + $table->integer('depth')->default(0); + }); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('contacts', function (Blueprint $table) { + $table->dropColumn('parent_id'); + $table->dropColumn('lft'); + $table->dropColumn('rgt'); + $table->dropColumn('depth'); + }); + } +}