mirror of
https://github.com/cp6/my-idlers.git
synced 2024-11-16 15:33:44 +01:00
Fixed locations cache
Fixed locations cache
This commit is contained in:
parent
6da3af1364
commit
d3125170e6
@ -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.');
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
]);
|
||||
|
@ -2,8 +2,9 @@
|
||||
<div class="input-group-prepend"><span class="input-group-text">{{ $title ??'Location'}}</span></div>
|
||||
<select class="form-control" name="{{$name ?? 'location_id'}}">
|
||||
@foreach ($locations as $location)
|
||||
<option value="{{ $location['id'] }}" {{(isset($current) && (string)$current === (string)$location['id'])? 'selected' : ''}}>
|
||||
{{ $location['name'] }}
|
||||
<option
|
||||
value="{{ $location->id }}" {{(isset($current) && (string)$current === (string)$location->id)? 'selected' : ''}}>
|
||||
{{ $location->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user