diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index d160966..e6f0e96 100644 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -31,7 +31,7 @@ class LocationsController extends Controller 'name' => $request->location_name ]); - Cache::forget('all_locations'); + Cache::forget('locations'); return redirect()->route('locations.index') ->with('success', 'Location Created Successfully.'); @@ -65,7 +65,7 @@ class LocationsController extends Controller $items->delete(); - Cache::forget('all_locations'); + Cache::forget('locations'); return redirect()->route('locations.index') ->with('success', 'Location was deleted Successfully.'); diff --git a/app/Models/Locations.php b/app/Models/Locations.php index 3151bc2..9956ebf 100644 --- a/app/Models/Locations.php +++ b/app/Models/Locations.php @@ -4,6 +4,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; class Locations extends Model { @@ -12,4 +14,11 @@ class Locations extends Model protected $fillable = ['name']; protected $table = 'locations'; + + public static function allLocations(): array + { + return Cache::remember("locations", now()->addMonth(1), function () { + return DB::table('locations')->get()->toArray(); + }); + } } diff --git a/app/View/Components/LocationsSelect.php b/app/View/Components/LocationsSelect.php index 1b2b9d8..fecde4b 100644 --- a/app/View/Components/LocationsSelect.php +++ b/app/View/Components/LocationsSelect.php @@ -15,9 +15,7 @@ class LocationsSelect extends Component */ public function render() { - $all_locations = Cache::rememberForever('all_locations', function () { - return Locations::all(); - }); + $all_locations = Locations::allLocations(); return view('components.locations-select', [ 'locations' => $all_locations ]); diff --git a/resources/views/components/locations-select.blade.php b/resources/views/components/locations-select.blade.php index 8c8cadb..87f3272 100644 --- a/resources/views/components/locations-select.blade.php +++ b/resources/views/components/locations-select.blade.php @@ -2,8 +2,9 @@
{{ $title ??'Location'}}