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

[9.x] Fix for model:show failing with models that have null timestamp columns #44576

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Oct 13, 2022

Motivation

I noticed that model:show currently fails with the following error for models with a null created_at or updated_at timestamp column:

   ErrorException

  array_flip(): Can only flip string and integer values, entry skipped

  at vendor/laravel/framework/src/Illuminate/Collections/Collection.php:406
    402▕      * @return static<TValue, TKey>
    403▕      */
    404▕     public function flip()
    405▕     {
  ➜ 406return new static(array_flip($this->items));
    407▕     }
    408409▕     /**
    410▕      * Remove an item from the collection by key.

      +4 vendor frames
  5   [internal]:0
      Illuminate\Foundation\Console\ShowModelCommand::Illuminate\Foundation\Console\{closure}(Object(Doctrine\DBAL\Schema\Column))

      +17 vendor frames
  23  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

The fix is to simply filter out any null results returned from $model->getDates() prior to flipping the collection.

@taylorotwell taylorotwell merged commit c7ffcc3 into laravel:9.x Oct 13, 2022
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

Successfully merging this pull request may close these issues.

2 participants