Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Argument supplied for foreach #11

Closed
priestd09 opened this issue Jan 5, 2017 · 3 comments
Closed

Invalid Argument supplied for foreach #11

priestd09 opened this issue Jan 5, 2017 · 3 comments

Comments

@priestd09
Copy link

priestd09 commented Jan 5, 2017

Laravel 5.3
I am getting an Invalid Argument supplied for foreach error when using php artisan code:models

I traced it back to Models line 1036

I fixed it by checking if primaryKeys->columns is an array before processing the foreach block
Updated code is below

Please confirm and add this possible fix if you want.

public function isPrimaryKey(Fluent $command)
    {
        if(is_array($this->primaryKeys->columns)){

            foreach ($this->primaryKeys->columns as $column) {
                if (! in_array($column, $command->columns)) {
                    return false;
                }
            }

        }

        return true;
    }
@CristianLlanos
Copy link
Member

I'll check it out. Thanks 😅

@CristianLlanos
Copy link
Member

Where you able to trace back in which of your tables this error happened? If so, would you mind sharing its structure with me? Does it have a primary key? No problem if you can't. Thanks in advance 👍

@priestd09
Copy link
Author

I tracked it to a table that didn't have a primary key
I confirmed by adding a primary key of id and I removed the aforementioned fix and no errors occurred
When I removed that primary key, then the error happened again.
I hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants