Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User extends Model {
- public function threads() {
- return $this->belongsToMany(Thread::class)->withPivot('last_read_message_id');
- }
- }
- class Thread extends Model {
- public function users() {
- return $this->belongsToMany(User::class)->withPivot('last_read_message_id');
- }
- public function messages() {
- return $this->hasMany(ThreadMessage::class);
- }
- }
- class ThreadMessage extends Model {
- public function thread() {
- return $this->belongsTo(Thread::class);
- }
- public function author() {
- return $this->belongsTo(User::class);
- }
- }
- // ...
- Auth::user()->threads;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement