Import the Correct Auth Facade
In DashboardController.php file, replace this incorrect import:
use Illuminate\Container\Attributes\Auth;
with the correct one:
use Illuminate\Support\Facades\Auth;
Then your index() function should be work.
Why did this happen?
You mistakenly imported Illuminate\Container\Attributes\Auth
, which
is not the correct Auth facade.
Blade templates (dashboard.blade.php) recognise Auth::user()
because Blade automatically provides access to facades.
However, Controller need the correct namespace
Illuminate\Support\Facades\Auth
.