Get all posts and check if user liked each post
问题 I'm trying to create an Eloquent query that fetches all posts and checks if the user liked each of those posts. I have the following models: Post.php class Post extends Eloquent { /** * The database table used by the model. * * @var string */ protected $table = 'posts'; public function user() { return $this->belongsTo('User'); } public function likes() { return $this->hasMany('Like'); } } Like.php : class Like extends Eloquent { /** * The database table used by the model. * * @var string */