Report.php 1002 B

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