You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\ContentReport;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property ContentReport $reportsOf
|
|
|
|
*/
|
|
|
|
trait Reportable
|
|
|
|
{
|
|
|
|
public static function bootReportable()
|
|
|
|
{
|
|
|
|
static::deleting(function($self) {
|
|
|
|
/** @var Reportable $self */
|
|
|
|
$self->reportsOf()->delete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reports of this user
|
|
|
|
*
|
|
|
|
* @return MorphMany
|
|
|
|
*/
|
|
|
|
public function reportsOf()
|
|
|
|
{
|
|
|
|
return $this->morphMany(ContentReport::class, 'object');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a report of this object to the DB
|
|
|
|
*
|
|
|
|
* @param string $message explanation why it should be removed
|
|
|
|
*/
|
|
|
|
public function reportAsInappropriate($message)
|
|
|
|
{
|
|
|
|
$this->reportsOf()->save(new ContentReport([
|
|
|
|
'author_id' => \Auth::user()->getKey(),
|
|
|
|
'message' => $message,
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
}
|