parent
6fd1d7eb89
commit
7493d3e176
@ -0,0 +1,29 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace App\Models\Concerns; |
||||
|
||||
|
||||
use App\Models\ContentReport; |
||||
use App\Models\Notification; |
||||
use Illuminate\Database\Eloquent\Relations\MorphMany; |
||||
|
||||
trait NotificationContext |
||||
{ |
||||
public function bootNotificationContext() |
||||
{ |
||||
static::deleting(function(NotificationContext $self) { |
||||
$self->notificationsAbout()->delete(); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Notifications having this model as a context |
||||
* |
||||
* @return MorphMany |
||||
*/ |
||||
public function notificationsAbout() |
||||
{ |
||||
return $this->morphMany(Notification::class, 'context'); |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace App\Models\Concerns; |
||||
|
||||
|
||||
use App\Models\ContentReport; |
||||
use Illuminate\Database\Eloquent\Relations\MorphMany; |
||||
|
||||
trait Reportable |
||||
{ |
||||
public function bootReportable() |
||||
{ |
||||
static::deleting(function(Reportable $self) { |
||||
$self->reportsOf()->delete(); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Reports of this user |
||||
* |
||||
* @return MorphMany |
||||
*/ |
||||
public function reportsOf() |
||||
{ |
||||
return $this->morphMany(ContentReport::class, 'object'); |
||||
} |
||||
} |
Loading…
Reference in new issue