2020-10-25 23:50:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-10-15 23:46:21 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-10-25 23:50:13 +01:00
|
|
|
|
|
|
|
class Group extends Model
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* model's array form.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = ['name'];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The accessors to append to the model's array form.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-09-21 22:43:39 +02:00
|
|
|
protected $appends = [];
|
2020-10-25 23:50:13 +01:00
|
|
|
|
|
|
|
|
2020-11-21 21:50:33 +01:00
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = ['created_at', 'updated_at'];
|
|
|
|
|
|
|
|
|
2020-11-23 12:54:06 +01:00
|
|
|
/**
|
|
|
|
* The attributes that should be cast.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'twofaccounts_count' => 'integer',
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2021-10-03 21:49:48 +02:00
|
|
|
/**
|
|
|
|
* Override The "booting" method of the model
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::deleting(function ($model) {
|
|
|
|
TwoFAccount::where('group_id', $model->id)
|
|
|
|
->update(
|
|
|
|
['group_id' => NULL]
|
|
|
|
);
|
|
|
|
});
|
2021-10-15 23:46:21 +02:00
|
|
|
|
|
|
|
static::deleted(function ($model) {
|
|
|
|
Log::info(sprintf('Group %s deleted', var_export($model->name, true)));
|
|
|
|
});
|
2021-10-03 21:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-25 23:50:13 +01:00
|
|
|
/**
|
|
|
|
* Get the TwoFAccounts of the group.
|
|
|
|
*/
|
|
|
|
public function twofaccounts()
|
|
|
|
{
|
|
|
|
return $this->hasMany('App\TwoFAccount');
|
|
|
|
}
|
|
|
|
}
|