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 ]); } }