winter/modules/backend/models/UserGroup.php

47 lines
1015 B
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace Backend\Models;
use October\Rain\Auth\Models\Group as GroupBase;
/**
* Administrator group
*
* @package october\backend
* @author Alexey Bobkov, Samuel Georges
*/
class UserGroup extends GroupBase
{
const CODE_OWNERS = 'owners';
2014-05-14 23:24:20 +10:00
/**
* @var string The database table used by the model.
*/
protected $table = 'backend_user_groups';
/**
* @var array Validation rules
*/
public $rules = [
2014-12-16 14:04:21 +11:00
'name' => 'required|between:2,128|unique:backend_user_groups',
2014-05-14 23:24:20 +10:00
];
/**
* @var array Relations
*/
public $belongsToMany = [
2017-05-20 20:01:19 +10:00
'users' => [User::class, 'table' => 'backend_users_groups'],
'users_count' => [User::class, 'table' => 'backend_users_groups', 'count' => true]
2014-05-14 23:24:20 +10:00
];
public function afterCreate()
{
if ($this->is_new_user_default) {
$this->addAllUsersToGroup();
}
}
public function addAllUsersToGroup()
{
$this->users()->sync(User::lists('id'));
}
2014-05-14 23:24:20 +10:00
}