User companies input change multi select groups
This commit is contained in:
@ -50,6 +50,15 @@ class User extends Authenticatable
|
||||
*/
|
||||
public $sortable = ['name', 'email', 'enabled'];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::retrieved(function($model) {
|
||||
$model->setCompanyIds();
|
||||
});
|
||||
}
|
||||
|
||||
public function companies()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Common\Company', 'user', 'user_companies', 'user_id', 'company_id');
|
||||
@ -169,4 +178,20 @@ class User extends Authenticatable
|
||||
{
|
||||
return $query->where('enabled', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to Array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCompanyIds()
|
||||
{
|
||||
$company_ids = [];
|
||||
|
||||
foreach ($this->companies as $company) {
|
||||
$company_ids[] = (string) $company->id;
|
||||
}
|
||||
|
||||
$this->setAttribute('company_ids', $company_ids);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user