Added all locations cache

Added all locations cache
This commit is contained in:
cp6 2022-03-03 14:43:54 +11:00
parent a005fc4576
commit 92bc68401a
2 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Locations; use App\Models\Locations;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -30,6 +31,8 @@ class LocationsController extends Controller
'name' => $request->location_name 'name' => $request->location_name
]); ]);
Cache::forget('all_locations');
return redirect()->route('locations.index') return redirect()->route('locations.index')
->with('success', 'Location Created Successfully.'); ->with('success', 'Location Created Successfully.');
} }
@ -62,6 +65,8 @@ class LocationsController extends Controller
$items->delete(); $items->delete();
Cache::forget('all_locations');
return redirect()->route('locations.index') return redirect()->route('locations.index')
->with('success', 'Location was deleted Successfully.'); ->with('success', 'Location was deleted Successfully.');
} }

View File

@ -3,6 +3,7 @@
namespace App\View\Components; namespace App\View\Components;
use App\Models\Locations; use App\Models\Locations;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\Component; use Illuminate\View\Component;
class LocationsSelect extends Component class LocationsSelect extends Component
@ -14,8 +15,11 @@ class LocationsSelect extends Component
*/ */
public function render() public function render()
{ {
$all_locations = Cache::rememberForever('all_locations', function () {
return Locations::all();
});
return view('components.locations-select', [ return view('components.locations-select', [
'locations' => Locations::all() 'locations' => $all_locations
]); ]);
} }
} }