*/ protected $hidden = ['created_at', 'updated_at']; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'twofaccounts_count' => 'integer', ]; /** * The event map for the model. * * @var array */ protected $dispatchesEvents = [ 'deleting' => GroupDeleting::class, 'deleted' => GroupDeleted::class, ]; /** * Override The "booting" method of the model * * @return void */ protected static function boot() { parent::boot(); static::created(function (object $model) { Log::info(sprintf('Group %s (id #%d) created for user ID #%s', var_export($model->name, true), $model->id, $model->user_id)); }); static::updated(function (object $model) { Log::info(sprintf('Group %s (id #%d) updated by user ID #%s', var_export($model->name, true), $model->id, $model->user_id)); }); static::deleted(function (object $model) { Log::info(sprintf('Group %s (id #%d) deleted ', var_export($model->name, true), $model->id)); }); } /** * Get the TwoFAccounts of the group. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function twofaccounts() { return $this->hasMany(\App\Models\TwoFAccount::class); } /** * Get the user that owns the group. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User, \App\Models\Group> */ public function user() { return $this->belongsTo(\App\Models\User::class); } /** * Scope a query to only include orphan (userless) groups. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOrphans($query) { return $query->where('user_id', null); } }