From 9fa830b4f9e462a2c1453183e3c394482d587ab0 Mon Sep 17 00:00:00 2001 From: Curtis Delicata Date: Mon, 29 Jul 2024 14:58:56 +0000 Subject: [PATCH] Add dynamic menu and site settings --- .../MenuResource/Pages/CreateMenu.php | 11 +++ .../Resources/MenuResource/Pages/EditMenu.php | 11 +++ .../MenuResource/Pages/ListMenus.php | 11 +++ .../Pages/CreateSiteSettings.php | 11 +++ .../Pages/EditSiteSettings.php | 19 +++++ .../Pages/ListSiteSettings.php | 19 +++++ app/Models/Menu.php | 28 ++++++++ database/factories/MenuFactory.php | 20 ++++++ ...5_25_000000_create_site_settings_table.php | 27 +++++++ .../2024_07_24_080000_create_menus_table.php | 28 ++++++++ database/seeders/MenuSeeder.php | 71 +++++++++++++++++++ database/seeders/SiteSettingsSeeder.php | 21 ++++++ 12 files changed, 277 insertions(+) create mode 100644 app/Filament/Admin/Resources/MenuResource/Pages/CreateMenu.php create mode 100644 app/Filament/Admin/Resources/MenuResource/Pages/EditMenu.php create mode 100644 app/Filament/Admin/Resources/MenuResource/Pages/ListMenus.php create mode 100644 app/Filament/Admin/Resources/SiteSettingsResource/Pages/CreateSiteSettings.php create mode 100644 app/Filament/Admin/Resources/SiteSettingsResource/Pages/EditSiteSettings.php create mode 100644 app/Filament/Admin/Resources/SiteSettingsResource/Pages/ListSiteSettings.php create mode 100644 app/Models/Menu.php create mode 100644 database/factories/MenuFactory.php create mode 100644 database/migrations/2023_05_25_000000_create_site_settings_table.php create mode 100644 database/migrations/2024_07_24_080000_create_menus_table.php create mode 100644 database/seeders/MenuSeeder.php create mode 100644 database/seeders/SiteSettingsSeeder.php diff --git a/app/Filament/Admin/Resources/MenuResource/Pages/CreateMenu.php b/app/Filament/Admin/Resources/MenuResource/Pages/CreateMenu.php new file mode 100644 index 00000000..bfaaf2b1 --- /dev/null +++ b/app/Filament/Admin/Resources/MenuResource/Pages/CreateMenu.php @@ -0,0 +1,11 @@ +belongsTo(Menu::class, 'parent_id'); + } + + public function children() + { + return $this->hasMany(Menu::class, 'parent_id'); + } +} diff --git a/database/factories/MenuFactory.php b/database/factories/MenuFactory.php new file mode 100644 index 00000000..12a7280d --- /dev/null +++ b/database/factories/MenuFactory.php @@ -0,0 +1,20 @@ + $this->faker->word, + 'url' => $this->faker->url, + 'order' => $this->faker->numberBetween(1, 10), + ]; + } +} \ No newline at end of file diff --git a/database/migrations/2023_05_25_000000_create_site_settings_table.php b/database/migrations/2023_05_25_000000_create_site_settings_table.php new file mode 100644 index 00000000..ccded418 --- /dev/null +++ b/database/migrations/2023_05_25_000000_create_site_settings_table.php @@ -0,0 +1,27 @@ +id(); + $table->string('name'); + $table->string('currency'); + $table->string('default_language'); + $table->text('address'); + $table->string('country'); + $table->string('email'); + $table->timestamps(); + }); + } + + public function down() + { + Schema::dropIfExists('site_settings'); + } +}; \ No newline at end of file diff --git a/database/migrations/2024_07_24_080000_create_menus_table.php b/database/migrations/2024_07_24_080000_create_menus_table.php new file mode 100644 index 00000000..1bf2841f --- /dev/null +++ b/database/migrations/2024_07_24_080000_create_menus_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('name'); + $table->string('url'); + $table->unsignedBigInteger('parent_id')->nullable(); + $table->integer('order')->default(0); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('parent_id')->references('id')->on('menus')->onDelete('cascade'); + }); + } + + public function down(): void + { + Schema::dropIfExists('menus'); + } +}; \ No newline at end of file diff --git a/database/seeders/MenuSeeder.php b/database/seeders/MenuSeeder.php new file mode 100644 index 00000000..06af3683 --- /dev/null +++ b/database/seeders/MenuSeeder.php @@ -0,0 +1,71 @@ + 'Home', + 'url' => '/', + 'order' => 1 + ], + [ + 'name' => 'Properties', + 'url' => '/properties', + 'order' => 2, + 'children' => [ + ['name' => 'For Sale', 'url' => '/properties/for-sale', 'order' => 1], + ['name' => 'For Rent', 'url' => '/properties/for-rent', 'order' => 2], + ] + ], + [ + 'name' => 'Services', + 'url' => '/services', + 'order' => 3, + 'children' => [ + ['name' => 'Buying', 'url' => '/services/buying', 'order' => 1], + ['name' => 'Selling', 'url' => '/services/selling', 'order' => 2], + ['name' => 'Renting', 'url' => '/services/renting', 'order' => 3], + ] + ], + [ + 'name' => 'About', + 'url' => '/about', + 'order' => 4 + ], + [ + 'name' => 'Contact', + 'url' => '/contact', + 'order' => 5 + ], + [ + 'name' => 'Calculators', + 'url' => '/calculators', + 'order' => 6 + ], + ]; + + foreach ($menus as $menuData) { + $this->createMenu($menuData); + } + } + + private function createMenu($menuData, $parentId = null) + { + $children = $menuData['children'] ?? []; + unset($menuData['children']); + + $menuData['parent_id'] = $parentId; + $menu = Menu::create($menuData); + + foreach ($children as $childData) { + $this->createMenu($childData, $menu->id); + } + } +} \ No newline at end of file diff --git a/database/seeders/SiteSettingsSeeder.php b/database/seeders/SiteSettingsSeeder.php new file mode 100644 index 00000000..dca08597 --- /dev/null +++ b/database/seeders/SiteSettingsSeeder.php @@ -0,0 +1,21 @@ + config('app.name', 'Liberu Real Estate'), + 'currency' => '£', + 'default_language' => 'en', + 'address' => '123 Real Estate St, London, UK', + 'country' => 'United Kingdom', + 'email' => 'info@liberurealestate.com', + ]); + } +} \ No newline at end of file