From 1a0661aec3815b8ee7a27a435f1c071e3d787929 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 9 Aug 2018 20:57:52 -0600 Subject: [PATCH] Update Report model, add new methods --- app/Report.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/Report.php diff --git a/app/Report.php b/app/Report.php new file mode 100644 index 00000000..879a8df3 --- /dev/null +++ b/app/Report.php @@ -0,0 +1,38 @@ +id); + } + + public function reporter() + { + return $this->belongsTo(Profile::class, 'profile_id'); + } + + public function reported() + { + $class = $this->object_type; + switch ($class) { + case 'App\Status': + $column = 'id'; + break; + + default: + $column = 'id'; + break; + } + return (new $class())->where($column, $this->object_id)->firstOrFail(); + } + + public function reportedUser() + { + return $this->belongsTo(Profile::class, 'reported_profile_id', 'id'); + } +}