Call to a member function addDays() on null

1.1k Views Asked by At

So I have a site for movie and tv-show reviews. It also gets most popular and latest movies/tv shows from IMDB or themoviedb. It is all okay with IMDB, but when I select tmdb as main movie data provider and click on a movie after that, I get an error "Call to a member function addDays() on null" Here is the code:

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

1

There are 1 best solutions below

0
On BEST ANSWER

This means updated_at is empty. You should make sure updated_at is not empty in all rows. You can set this column as not nullable:

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

Or check it for null:

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