Undefined variable error when I tried to display count in the dashboard page
I try to display count for number of tools in my dashboard page. However, it shows error:
Undefined variable $jumlahalat
web.php:
Route::get('/dashboard-admin', function () {
$jumlahalat = Inventory::count();
return view('dashboard-admin', compact('jumlahalat'));
});
dashboard-admin.blade.php:
<div class="grid grid-cols-4 gap-4 rounded mt-4 text-md font-bold text-[#fecbcf] w-full">
<a href="{{ url('/sda/alat') }}" class="text-white" style="text-decoration: none; color: inherit;">
<div class="bg-[#5479f7] flex gap-3 pl-5 justify-start items-center rounded-lg h-[110px]">
<div class="h-[70px] w-[70px] rounded-sm bg-white flex justify-center items-center">
<span class="material-icons text-black" style="font-size: 40px">inventory_2</span>
</div>
<div>
<div class="self-center text-start">Jumlah Alat</div>
<div class="self-center text-start">{{ $jumlahalat }}</div>
</div>
</div>
</a>
</div>
I already defined use AppModelsInventory
in web.php
2
Answers
This also might be just route/view cache issue.
Try to run these commands on your project
and also
if you try to do this counter on your dashboard….
then you can try on my way…..
on your controller. you can simply return all of your model….