Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class User extends Model {
  2. public function threads() {
  3. return $this->belongsToMany(Thread::class)->withPivot('last_read_message_id');
  4. }
  5. }
  6.  
  7. class Thread extends Model {
  8. public function users() {
  9. return $this->belongsToMany(User::class)->withPivot('last_read_message_id');
  10. }
  11.  
  12. public function messages() {
  13. return $this->hasMany(ThreadMessage::class);
  14. }
  15. }
  16.  
  17. class ThreadMessage extends Model {
  18. public function thread() {
  19. return $this->belongsTo(Thread::class);
  20. }
  21.  
  22. public function author() {
  23. return $this->belongsTo(User::class);
  24. }
  25. }
  26.  
  27. // ...
  28. Auth::user()->threads;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement