在 null 上调用成员函数 addDays()

Call to a member function addDays() on null

所以我有一个电影和电视节目评论网站。它还从 IMDB 或 themoviedb 获取最受欢迎和最新的 movies/tv 节目。 IMDB 没问题,但是当我 select tmdb 作为主要电影数据提供者并点击电影之后,我得到一个错误 "Call to a member function addDays() on null" 这是代码:

if ($title->review->isEmpty() && $date < Carbon::now()->toDateString() && $title->updated_at->addDays(1) <= Carbon::now())

这意味着 updated_at 是空的。您应该确保 updated_at 在所有行中都不为空。您可以将此列设置为不可为空:

$table->timestamps(); // Instead of nullableTimestamps()

或检查 null:

if ($title->review->isEmpty()
    && $date < Carbon::now()->toDateString() 
    && !is_null($title->updated_at)
    && $title->updated_at->addDays(1) <= Carbon::now())