php - syntax error, unexpected 'foreach' (T_FOREACH) using laravel 6
one text
Solution:
@foreach @endforeach used in blade syntax, try below syntax in controller
public function index()
{
$users = User::where('id', Auth::user()->id)->get();
foreach ($users as $user) {
dd($user->name);
}
return view('users.index', ['users' => $users]);
}
But there is a misconception if you are querying with primary key you can easily find a user by find() method as below
$user = User::find(Auth::user()->id);
$name= $user->name;
Source