Jeffry already covered this topic a couple times i think:
https://laracasts.com/series/whatcha-working-on/episodes/33 and in the TDD series https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/56
Hi all. I'm trying to figure out how to setup my models and relationships to store @username mentions. Here's the basic DB schema I want:
comments
- body = (text) <string of text containing @username mentions>
- ...
posts
- body = (text) <string of text containing @username mentions>
- ...
users
- id = (int)
- ...
mentions
- model_type = (varchar) App\Models\Comment | App\Models\Post
- model_id = (int)
- user_id (int)
- created_at (datetime)
- updated_at (datetime)
I want to be able to use $comment->mentions and $post->mentions to retrieve users mentioned in the post, and $user->mentions to retrieve posts and comments that have mentioned the user, and use the Eloquent attach/detach/sync methods to manage the relationships..
I believe mentions should be a pivot model, but I'm struggling to wrap my head around how to set this up past that.
Please or to participate in this conversation.