Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
28.57% |
2 / 7 |
CRAP | |
16.67% |
2 / 12 |
| User | |
0.00% |
0 / 1 |
|
28.57% |
2 / 7 |
67.87 | |
16.67% |
2 / 12 |
| roles | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| permissions | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| helpNeededs | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| completedHelpNeededs | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| comptabilityCompanies | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getEntitiesAttribute | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
| setEntitiesAttribute | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 6 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\Acls\Models; |
| 4 | |
| 5 | use Illuminate\Notifications\Notifiable; |
| 6 | use Illuminate\Foundation\Auth\User as Authenticatable; |
| 7 | |
| 8 | use Illuminate\Support\Collection; |
| 9 | use Qmp\Laravel\Acls\Models\Role; |
| 10 | use Qmp\Laravel\Acls\Models\Permission; |
| 11 | use Qmp\Laravel\Compta\Models\Company; |
| 12 | |
| 13 | class User extends Authenticatable |
| 14 | { |
| 15 | use Notifiable; |
| 16 | |
| 17 | |
| 18 | protected $connection = 'mysql'; |
| 19 | |
| 20 | protected $primaryKey = "id"; |
| 21 | |
| 22 | /** |
| 23 | * The attributes that are mass assignable. |
| 24 | * |
| 25 | * @var array |
| 26 | */ |
| 27 | protected $fillable = [ |
| 28 | 'id', 'email', 'entities' |
| 29 | ]; |
| 30 | |
| 31 | /** |
| 32 | * The attributes that should be hidden for arrays. |
| 33 | * |
| 34 | * @var array |
| 35 | */ |
| 36 | protected $hidden = []; |
| 37 | |
| 38 | protected $appends = []; |
| 39 | |
| 40 | public function roles() |
| 41 | { |
| 42 | return $this->belongsToMany(Role::class); |
| 43 | } |
| 44 | |
| 45 | public function permissions() |
| 46 | { |
| 47 | return $this->belongsToMany(Permission::class); |
| 48 | } |
| 49 | |
| 50 | public function helpNeededs() |
| 51 | { |
| 52 | return $this->hasMany('App\HelpNeeded', 'user_id', 'id'); |
| 53 | } |
| 54 | |
| 55 | public function completedHelpNeededs() |
| 56 | { |
| 57 | return $this->hasMany('App\HelpNeeded', 'completed_by', 'id'); |
| 58 | } |
| 59 | |
| 60 | public function comptabilityCompanies() |
| 61 | { |
| 62 | return $this->belongsToMany(Company::class); |
| 63 | } |
| 64 | |
| 65 | public function getEntitiesAttribute($value) |
| 66 | { |
| 67 | return !empty($value) ? explode(',', $value) : []; |
| 68 | } |
| 69 | |
| 70 | public function setEntitiesAttribute($value) |
| 71 | { |
| 72 | if(is_array($value)) { |
| 73 | $this->attributes['entities'] = implode(',', $value); |
| 74 | } elseif ($value instanceof Collection) { |
| 75 | $this->attributes['entities'] = implode(',', $value->toArray()); |
| 76 | } else { |
| 77 | throw new \Exception('Invalid data for entities attribute, array or collection needed'); |
| 78 | } |
| 79 | } |
| 80 | } |