Skip to content
Advertisement

Laravel @foreach – invalid argument supplied

I am very new to Laravel and PHP, just trying to list all users in my view file like this:

JavaScript

But getting an error which says ‘Invalid argument supplied for foreach()’

In my controller, I have the following function:

JavaScript

What am I doing wrong?

Advertisement

Answer

$users is not defined in your controller, but $user is. You are trying to @foreach over a variable that literally equals the string '$users'. Change:

JavaScript

to:

JavaScript

And remove the single quotes around $users:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement