1
0
mirror of https://github.com/cp6/my-idlers.git synced 2024-11-16 15:33:44 +01:00

Fixed providers cache

Fixed providers cache
This commit is contained in:
cp6 2022-05-09 15:39:03 +10:00
parent d3125170e6
commit 1251fae0df
8 changed files with 19 additions and 12 deletions

View File

@ -43,7 +43,7 @@ class DomainsController extends Controller
public function create()
{
$Providers = Providers::all();
$Providers = Providers::allProviders();
return view('domains.create', compact('Providers'));
}

View File

@ -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.');

View File

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

View File

@ -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']));

View File

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

View File

@ -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();
});
}
}

View File

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

View File

@ -2,8 +2,8 @@
<div class="input-group-prepend"><span class="input-group-text">{{ $title ??'Provider'}}</span></div>
<select class="form-control" name="{{$name ?? 'provider_id'}}">
@foreach ($providers as $provider)
<option value="{{ $provider['id'] }}" {{(isset($current) && (string)$current === (string)$provider['id'])? 'selected' : ''}}>
{{ $provider['name'] }}
<option value="{{ $provider->id }}" {{(isset($current) && (string)$current === (string)$provider->id)? 'selected' : ''}}>
{{ $provider->name }}
</option>
@endforeach
</select>