some work on models
This commit is contained in:
@@ -3,14 +3,21 @@
|
||||
namespace App\Models;
|
||||
|
||||
use AdamWathan\EloquentOAuth\OAuthIdentity;
|
||||
use App\Models\Concerns\Reportable;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
/**
|
||||
* A user in the application
|
||||
*
|
||||
* @property Proposal[]|Collection $proposals
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Reportable;
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
@@ -31,6 +38,20 @@ class User extends Authenticatable
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function(User $self) {
|
||||
// manually delete proposals to ensure row refcounts are updated
|
||||
foreach ($self->proposals as $proposal) {
|
||||
$proposal->delete();
|
||||
}
|
||||
|
||||
$self->notificationsCaused()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/** Owned tables */
|
||||
public function dataTables()
|
||||
{
|
||||
@@ -78,4 +99,14 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(Notification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications caused by this user
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function notificationsCaused()
|
||||
{
|
||||
return $this->hasMany(Notification::class, 'actor_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user