Added all labels cache

Added all labels cache
This commit is contained in:
cp6 2022-03-03 14:45:32 +11:00
parent 92bc68401a
commit 01cf83a31c
2 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Labels;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@ -32,6 +33,8 @@ class LabelsController extends Controller
'label' => $request->label
]);
Cache::forget('all_labels');
return redirect()->route('labels.index')
->with('success', 'Label Created Successfully.');
}
@ -65,6 +68,8 @@ class LabelsController extends Controller
Labels::deleteLabelAssignedAs($label_id);
Cache::forget('all_labels');
return redirect()->route('labels.index')
->with('success', 'Label was deleted Successfully.');
}

View File

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