From f923eef8683ebfadf923f5b786b53a7efe822f92 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Wed, 25 Jan 2023 22:32:59 +0100 Subject: [PATCH 1/5] Useful Links in Topbar --- .../Admin/UsefulLinkController.php | 17 ++++++++-- app/Models/UsefulLink.php | 1 + app/Providers/AppServiceProvider.php | 7 ++++ ...1_25_204343_useful_links_on_top_navbar.php | 32 +++++++++++++++++++ .../views/admin/usefullinks/create.blade.php | 15 +++++++++ .../views/admin/usefullinks/edit.blade.php | 15 +++++++++ .../views/admin/usefullinks/index.blade.php | 2 ++ themes/default/views/layouts/main.blade.php | 9 ++++-- 8 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php diff --git a/app/Http/Controllers/Admin/UsefulLinkController.php b/app/Http/Controllers/Admin/UsefulLinkController.php index ea51c37d..df66e834 100644 --- a/app/Http/Controllers/Admin/UsefulLinkController.php +++ b/app/Http/Controllers/Admin/UsefulLinkController.php @@ -48,7 +48,14 @@ class UsefulLinkController extends Controller 'description' => 'required|string|max:2000', ]); - UsefulLink::create($request->all()); + + UsefulLink::create([ + 'icon' => $request->icon, + 'title' => $request->title, + 'link' => $request->link, + 'description' => $request->description, + 'navbar' => $request->navbar, + ]); return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!')); } @@ -93,7 +100,13 @@ class UsefulLinkController extends Controller 'description' => 'required|string|max:2000', ]); - $usefullink->update($request->all()); + $usefullink->update([ + 'icon' => $request->icon, + 'title' => $request->title, + 'link' => $request->link, + 'description' => $request->description, + 'navbar' => $request->navbar, + ]); return redirect()->route('admin.usefullinks.index')->with('success', __('link has been updated!')); } diff --git a/app/Models/UsefulLink.php b/app/Models/UsefulLink.php index 4d788e0d..d040eadd 100644 --- a/app/Models/UsefulLink.php +++ b/app/Models/UsefulLink.php @@ -16,5 +16,6 @@ class UsefulLink extends Model 'title', 'link', 'description', + 'navbar', ]; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e9390b6e..40aa0b29 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Models\Settings; +use App\Models\UsefulLink; use Exception; use Illuminate\Pagination\Paginator; use Illuminate\Support\Facades\Artisan; @@ -53,6 +54,12 @@ class AppServiceProvider extends ServiceProvider return $ok; }); + + if (Schema::hasColumn('useful_links', 'navbar')) { + $useful_links = UsefulLink::where("navbar", "true")->get(); + view()->share('useful_links', $useful_links); + } + //only run if the installer has been executed try { $settings = Settings::all(); 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 new file mode 100644 index 00000000..46c3b027 --- /dev/null +++ b/database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php @@ -0,0 +1,32 @@ +string('navbar')->after("description")->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('useful_links', function (Blueprint $table) { + $table->dropColumn('navbar'); + }); + } +}; diff --git a/themes/default/views/admin/usefullinks/create.blade.php b/themes/default/views/admin/usefullinks/create.blade.php index 53f68509..dd1b2824 100644 --- a/themes/default/views/admin/usefullinks/create.blade.php +++ b/themes/default/views/admin/usefullinks/create.blade.php @@ -94,6 +94,21 @@ @enderror +
+
+
+ + +
+
+ @error('navbar') +
+ {{$message}} +
+ @enderror +
+
+
+
+
+ navbar == "true") checked @endif + +
+
+ @error('navbar') +
+ {{$message}} +
+ @enderror +
+
- From b343134c010d4b13cefadd166761c62592533cf0 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Thu, 26 Jan 2023 15:22:42 +0100 Subject: [PATCH 3/5] 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 @@