Hello everyone,
I'm new to laravel and I'm following this tutorial where I'm making a clone of Twitter. I'm making a like/dislike system for tweets, and I'm using this code for a function:
public function isLikedBy(User $user)
{
return (bool) $user->likes
->where('tweet_id', $this->id)
->where('liked', true)
->count();
}
If I run it in Tinker, this is my code:
$user = App\User::first(); // works fine
$tweet = App\Tweet::first(); // works also fine
$tweet->like($user); // is also working
$tweet->isLikedBy($user); // I got the following error
And this is my error:
PHP Error: Call to a member function where() on null in C:/wamp64/www/laravel/tweety/app/Tweet.php on line 32
I guess it has something to do with $user->likes, but I'm not sure. I've dubble dubble dubble checked if I made an type mistake, but my code is the same as the code from the teacher.
Does anyone know what to do now?
If you need more information, please ask me.
Thank you! Jeroen