pixelfed/app/Report.php

42 lines
787 B
PHP
Raw Normal View History

2018-08-10 02:57:52 +00:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Report extends Model
{
2018-08-26 06:00:20 +00:00
protected $dates = ['admin_seen'];
2018-08-28 03:07:36 +00:00
2018-08-10 02:57:52 +00:00
public function url()
{
2018-08-28 03:07:36 +00:00
return url('/i/admin/reports/show/'.$this->id);
2018-08-10 02:57:52 +00:00
}
public function reporter()
{
2018-08-28 03:07:36 +00:00
return $this->belongsTo(Profile::class, 'profile_id');
2018-08-10 02:57:52 +00:00
}
public function reported()
{
2018-08-28 03:07:36 +00:00
$class = $this->object_type;
switch ($class) {
2018-08-10 02:57:52 +00:00
case 'App\Status':
$column = 'id';
break;
2018-08-28 03:07:36 +00:00
2018-08-10 02:57:52 +00:00
default:
$column = 'id';
break;
}
2018-08-28 03:07:36 +00:00
return (new $class())->where($column, $this->object_id)->firstOrFail();
2018-08-10 02:57:52 +00:00
}
public function reportedUser()
{
2018-08-28 03:07:36 +00:00
return $this->belongsTo(Profile::class, 'reported_profile_id', 'id');
2018-08-10 02:57:52 +00:00
}
}