Report.php 947 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Report extends Model
  5. {
  6. protected $dates = ['admin_seen'];
  7. public function url()
  8. {
  9. return url('/i/admin/reports/show/'.$this->id);
  10. }
  11. public function reporter()
  12. {
  13. return $this->belongsTo(Profile::class, 'profile_id');
  14. }
  15. public function reported()
  16. {
  17. $class = $this->object_type;
  18. switch ($class) {
  19. case 'App\Status':
  20. $column = 'id';
  21. break;
  22. default:
  23. $class = 'App\Status';
  24. $column = 'id';
  25. break;
  26. }
  27. return (new $class())->where($column, $this->object_id)->first();
  28. }
  29. public function status()
  30. {
  31. return $this->belongsTo(Status::class, 'object_id');
  32. }
  33. public function reportedUser()
  34. {
  35. return $this->belongsTo(Profile::class, 'reported_profile_id', 'id');
  36. }
  37. }