DirectMessage.php 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. class DirectMessage extends Model
  6. {
  7. public function status()
  8. {
  9. return $this->belongsTo(Status::class, 'status_id', 'id');
  10. }
  11. public function url()
  12. {
  13. return config('app.url') . '/account/direct/m/' . $this->status_id;
  14. }
  15. public function author()
  16. {
  17. return $this->belongsTo(Profile::class, 'from_id', 'id');
  18. }
  19. public function recipient()
  20. {
  21. return $this->belongsTo(Profile::class, 'to_id', 'id');
  22. }
  23. public function me()
  24. {
  25. return Auth::user()->profile->id === $this->from_id;
  26. }
  27. public function toText()
  28. {
  29. $actorName = $this->author->username;
  30. return "{$actorName} sent a direct message.";
  31. }
  32. public function toHtml()
  33. {
  34. $actorName = $this->author->username;
  35. $actorUrl = $this->author->url();
  36. $url = $this->url();
  37. return "{$actorName} sent a direct message.";
  38. }
  39. }