mercredi 3 janvier 2018

Flag a relationship?

I have posts and users models. A user can bookmark a post. I store these bookmarks in a pivot table that has user_id and post_id on it.

I need to get all posts out and flag if the current logged in user has bookmarked the post (to add a class to an icon).

return Post::with('bookmarks')->get();

The above gets all bookmarks for a post, how can I flag it so that I know if the logged in user has bookmarked a particular post?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire