First tell me from where you are returning the dashboard.blade.php
- Are you passing your data
$statsto that dashboard view ..
And make sure to place your code in between three start and three end backticks ``` like this .
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello i'm getting Undifined variable $stats, (this is just test code I wrote) I don't think my logic is correct, it must not be.
this is my InventoryController.php $stats = [ 'total_items' => InventoryItem::count(), 'pending_items' => InventoryItem::where('Status', 'Pending')->count(), 'accepted_items' => InventoryItem::where('Status', 'Accepted')->count(), 'rejected_items' => InventoryItem::where('Status', 'Rejected')->count(), ];
and route Route::prefix('inventory')->name('inventory.')->group(function () { Route::get('/dashboard', [InventoryController::class, 'dashboard'])->name('inventory.dashboard'); Route::get('/create', [InventoryController::class, 'create'])->name('inventory.create'); Route::post('/store', [InventoryController::class, 'store'])->name('inventory.store'); Route::get('item/{item}', [InventoryController::class, 'show'])->name('inventory.show'); Route::post('item/{item}/accept', [InventoryController::class, 'accept'])->name('inventory.accept'); Route::post('item/{item}/reject', [InventoryController::class, 'reject'])->name('inventory.reject'); });
i'm use @extends('layouts.app') in dashboard.blade.php (resources/views/inventory/dashboard.blade.php) Total Items {{ $stats['total'] }}
my app.blade.php (resources/views/layouts/app.blade.php)
<main class="max-w-7xl mx-auto py-6 px-4">
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
{{ session('success') }}
</div>
@endif
@if(session('error'))
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
{{ session('error') }}
</div>
@endif
@yield('content')
</main>
Please or to participate in this conversation.