From 92bc68401acbfe8767bd22715864b557adf16ba3 Mon Sep 17 00:00:00 2001 From: cp6 Date: Thu, 3 Mar 2022 14:43:54 +1100 Subject: [PATCH] Added all locations cache Added all locations cache --- app/Http/Controllers/LocationsController.php | 5 +++++ app/View/Components/LocationsSelect.php | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 88080e9..d160966 100644 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Models\Locations; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; @@ -30,6 +31,8 @@ class LocationsController extends Controller 'name' => $request->location_name ]); + Cache::forget('all_locations'); + return redirect()->route('locations.index') ->with('success', 'Location Created Successfully.'); } @@ -62,6 +65,8 @@ class LocationsController extends Controller $items->delete(); + Cache::forget('all_locations'); + return redirect()->route('locations.index') ->with('success', 'Location was deleted Successfully.'); } diff --git a/app/View/Components/LocationsSelect.php b/app/View/Components/LocationsSelect.php index ba460ab..1b2b9d8 100644 --- a/app/View/Components/LocationsSelect.php +++ b/app/View/Components/LocationsSelect.php @@ -3,6 +3,7 @@ namespace App\View\Components; use App\Models\Locations; +use Illuminate\Support\Facades\Cache; use Illuminate\View\Component; class LocationsSelect extends Component @@ -14,8 +15,11 @@ class LocationsSelect extends Component */ public function render() { + $all_locations = Cache::rememberForever('all_locations', function () { + return Locations::all(); + }); return view('components.locations-select', [ - 'locations' => Locations::all() + 'locations' => $all_locations ]); } }