Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
calebdw:bugfix-model_show
Oct 13, 2022
Merged

[9.x] Fix for model:show failing with models that have null timestamp columns#44576
taylorotwell merged 1 commit into
laravel:9.xfrom
calebdw:bugfix-model_show

Conversation

@calebdw

@calebdw calebdw commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

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