I have a DateTime Object, and I have many posts belonging to a User. My Relationship on the User model is set up like:
public function posts()
{
return $this->hasMany('App\Post');
}
I can retrieve the logged in user's posts by doing:
Auth::user()->posts
However, I can't seem to retrieve posts that were made after a certain date. I tried:
/** \DateTime $date **/
$posts = \Auth::user()->posts->where('created_at','>', $date);
But it just returns an empty array and I'm certain that there are posts which exist that were created after that date. What is the correct way to perform this query?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire