diff --git a/app/Http/Controllers/DomainsController.php b/app/Http/Controllers/DomainsController.php index 5b7aa03..ff8c364 100644 --- a/app/Http/Controllers/DomainsController.php +++ b/app/Http/Controllers/DomainsController.php @@ -43,7 +43,7 @@ class DomainsController extends Controller public function create() { - $Providers = Providers::all(); + $Providers = Providers::allProviders(); return view('domains.create', compact('Providers')); } diff --git a/app/Http/Controllers/ProvidersController.php b/app/Http/Controllers/ProvidersController.php index 7002c78..2da272a 100644 --- a/app/Http/Controllers/ProvidersController.php +++ b/app/Http/Controllers/ProvidersController.php @@ -12,7 +12,7 @@ class ProvidersController extends Controller { public function index() { - $providers = Providers::all(); + $providers = Providers::allProviders(); return view('providers.index', compact(['providers'])); } @@ -31,7 +31,7 @@ class ProvidersController extends Controller 'name' => $request->provider_name ]); - Cache::forget('all_providers'); + Cache::forget('providers'); return redirect()->route('providers.index') ->with('success', 'Provider Created Successfully.'); @@ -65,7 +65,7 @@ class ProvidersController extends Controller $items->delete(); - Cache::forget('all_providers'); + Cache::forget('providers'); return redirect()->route('providers.index') ->with('success', 'Provider was deleted Successfully.'); diff --git a/app/Http/Controllers/ResellerController.php b/app/Http/Controllers/ResellerController.php index 863705e..08181c7 100644 --- a/app/Http/Controllers/ResellerController.php +++ b/app/Http/Controllers/ResellerController.php @@ -28,7 +28,7 @@ class ResellerController extends Controller public function create() { - $Providers = Providers::all(); + $Providers = Providers::allProviders(); $Locations = Locations::all(); return view('reseller.create', compact(['Providers', 'Locations'])); } diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index eb9a1ab..35677d2 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -81,7 +81,7 @@ class ServerController extends Controller public function create() { - $Providers = Providers::all(); + $Providers = Providers::allProviders(); $Locations = Locations::all(); $Os = OS::allOS(); return view('servers.create', compact(['Providers', 'Locations', 'Os'])); diff --git a/app/Http/Controllers/SharedController.php b/app/Http/Controllers/SharedController.php index a9c1360..6131e9d 100644 --- a/app/Http/Controllers/SharedController.php +++ b/app/Http/Controllers/SharedController.php @@ -28,7 +28,7 @@ class SharedController extends Controller public function create() { - $Providers = Providers::all(); + $Providers = Providers::allProviders(); $Locations = Locations::all(); return view('shared.create', compact(['Providers', 'Locations'])); } diff --git a/app/Models/Providers.php b/app/Models/Providers.php index 8a70ebd..cee3581 100644 --- a/app/Models/Providers.php +++ b/app/Models/Providers.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 Providers extends Model { @@ -12,4 +14,11 @@ class Providers extends Model protected $fillable = ['name']; protected $table = 'providers'; + + public static function allProviders(): array + { + return Cache::remember("providers", now()->addMonth(1), function () { + return DB::table('providers')->get()->toArray(); + }); + } } diff --git a/app/View/Components/ProvidersSelect.php b/app/View/Components/ProvidersSelect.php index f169257..64c45f8 100644 --- a/app/View/Components/ProvidersSelect.php +++ b/app/View/Components/ProvidersSelect.php @@ -16,9 +16,7 @@ class ProvidersSelect extends Component */ public function render() { - $all_providers = Cache::rememberForever('all_providers', function () { - return Providers::all(); - }); + $all_providers = Providers::allProviders(); return view('components.providers-select', [ 'providers' => $all_providers ]); diff --git a/resources/views/components/providers-select.blade.php b/resources/views/components/providers-select.blade.php index ebf8bd2..4f33d5f 100644 --- a/resources/views/components/providers-select.blade.php +++ b/resources/views/components/providers-select.blade.php @@ -2,8 +2,8 @@