From b343134c010d4b13cefadd166761c62592533cf0 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Thu, 26 Jan 2023 15:22:42 +0100 Subject: [PATCH] using enums, adding more positions --- app/Enums/UsefulLinkLocation.php | 19 ++++++++++++++++++ .../Admin/UsefulLinkController.php | 10 +++++++--- app/Http/Controllers/HomeController.php | 2 +- app/Models/UsefulLink.php | 2 +- app/Providers/AppServiceProvider.php | 4 ++-- ...1_25_204343_useful_links_on_top_navbar.php | 4 ++-- .../views/admin/usefullinks/create.blade.php | 20 +++++++++++-------- .../views/admin/usefullinks/edit.blade.php | 18 +++++++++-------- .../views/admin/usefullinks/index.blade.php | 4 ++-- themes/default/views/layouts/main.blade.php | 14 +++++++------ 10 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 app/Enums/UsefulLinkLocation.php diff --git a/app/Enums/UsefulLinkLocation.php b/app/Enums/UsefulLinkLocation.php new file mode 100644 index 00000000..b43162ba --- /dev/null +++ b/app/Enums/UsefulLinkLocation.php @@ -0,0 +1,19 @@ +with('positions', $positions); } /** @@ -54,7 +56,7 @@ class UsefulLinkController extends Controller 'title' => $request->title, 'link' => $request->link, 'description' => $request->description, - 'navbar' => $request->navbar, + 'position' => implode(",",$request->position), ]); return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!')); @@ -79,8 +81,10 @@ class UsefulLinkController extends Controller */ public function edit(UsefulLink $usefullink) { + $positions = UsefulLinkLocation::cases(); return view('admin.usefullinks.edit', [ 'link' => $usefullink, + 'positions' => $positions, ]); } @@ -105,7 +109,7 @@ class UsefulLinkController extends Controller 'title' => $request->title, 'link' => $request->link, 'description' => $request->description, - 'navbar' => $request->navbar, + 'position' => implode(",",$request->position), ]); return redirect()->route('admin.usefullinks.index')->with('success', __('link has been updated!')); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index ce72d947..23b41bb0 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -111,7 +111,7 @@ class HomeController extends Controller return view('home')->with([ 'usage' => $usage, 'credits' => $credits, - 'useful_links' => UsefulLink::all()->sortBy('id'), + 'useful_links' => UsefulLink::where("position","like","%dashboard%")->get()->sortby("id"), 'bg' => $bg, 'boxText' => $boxText, 'unit' => $unit, diff --git a/app/Models/UsefulLink.php b/app/Models/UsefulLink.php index d040eadd..c54f3d26 100644 --- a/app/Models/UsefulLink.php +++ b/app/Models/UsefulLink.php @@ -16,6 +16,6 @@ class UsefulLink extends Model 'title', 'link', 'description', - 'navbar', + 'position', ]; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 40aa0b29..b20e4fdd 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -55,8 +55,8 @@ class AppServiceProvider extends ServiceProvider }); - if (Schema::hasColumn('useful_links', 'navbar')) { - $useful_links = UsefulLink::where("navbar", "true")->get(); + if (Schema::hasColumn('useful_links', 'position')) { + $useful_links = UsefulLink::get(); view()->share('useful_links', $useful_links); } diff --git a/database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php b/database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php index 46c3b027..cfaacf35 100644 --- a/database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php +++ b/database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php @@ -14,7 +14,7 @@ return new class extends Migration public function up() { Schema::table('useful_links', function (Blueprint $table) { - $table->string('navbar')->after("description")->nullable(); + $table->string('position')->after("description")->nullable(); }); } @@ -26,7 +26,7 @@ return new class extends Migration public function down() { Schema::table('useful_links', function (Blueprint $table) { - $table->dropColumn('navbar'); + $table->dropColumn('position'); }); } }; diff --git a/themes/default/views/admin/usefullinks/create.blade.php b/themes/default/views/admin/usefullinks/create.blade.php index dd1b2824..b7174657 100644 --- a/themes/default/views/admin/usefullinks/create.blade.php +++ b/themes/default/views/admin/usefullinks/create.blade.php @@ -95,14 +95,15 @@
-
-
- - -
-
- @error('navbar') + + @error('position')
{{$message}}
@@ -126,6 +127,7 @@ @endsection diff --git a/themes/default/views/admin/usefullinks/edit.blade.php b/themes/default/views/admin/usefullinks/edit.blade.php index 86062c04..11b51605 100644 --- a/themes/default/views/admin/usefullinks/edit.blade.php +++ b/themes/default/views/admin/usefullinks/edit.blade.php @@ -96,14 +96,15 @@
-
-
- navbar == "true") checked @endif - -
-
- @error('navbar') + + @error('position')
{{$message}}
@@ -128,6 +129,7 @@