2FAuth/app/Models/Group.php

89 lines
1.6 KiB
PHP
Raw Normal View History

2020-10-25 23:50:13 +01:00
<?php
2021-12-02 13:15:53 +01:00
namespace App\Models;
2020-10-25 23:50:13 +01:00
use App\Events\GroupDeleting;
2020-10-25 23:50:13 +01:00
use Illuminate\Database\Eloquent\Model;
2021-10-15 23:46:21 +02:00
use Illuminate\Support\Facades\Log;
2021-12-02 13:15:53 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2020-10-25 23:50:13 +01:00
/**
* @property int $twofaccounts_count
*/
2020-10-25 23:50:13 +01:00
class Group extends Model
{
2021-12-02 13:15:53 +01:00
use HasFactory;
2020-10-25 23:50:13 +01:00
/**
* model's array form.
*
* @var string[]
2020-10-25 23:50:13 +01:00
*/
protected $fillable = ['name'];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [];
2020-10-25 23:50:13 +01:00
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
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,
];
/**
* Override The "booting" method of the model
*
* @return void
*/
protected static function boot()
{
parent::boot();
2021-10-15 23:46:21 +02:00
static::deleted(function (object $model) {
2021-11-30 17:39:33 +01:00
// @codeCoverageIgnoreStart
2021-10-15 23:46:21 +02:00
Log::info(sprintf('Group %s deleted', var_export($model->name, true)));
2021-11-30 17:39:33 +01:00
// @codeCoverageIgnoreEnd
2021-10-15 23:46:21 +02:00
});
}
2020-10-25 23:50:13 +01:00
/**
* Get the TwoFAccounts of the group.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
2020-10-25 23:50:13 +01:00
*/
public function twofaccounts()
{
return $this->hasMany(\App\Models\TwoFAccount::class);
2020-10-25 23:50:13 +01:00
}
}