User::hasProfile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Illuminate\Foundation\Auth\User as Authenticatable;
8
use Illuminate\Notifications\Notifiable;
9
use jeremykenedy\LaravelRoles\Traits\HasRoleAndPermission;
10
11
class User extends Authenticatable
12
{
13
    use HasRoleAndPermission;
0 ignored issues
show
introduced by
The trait jeremykenedy\LaravelRole...ts\HasRoleAndPermission requires some properties which are not provided by App\Models\User: $model, $slug, $level
Loading history...
14
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\Models\User: $email, $phone_number
Loading history...
15
    use SoftDeletes;
16
17
    /**
18
     * The database table used by the model.
19
     *
20
     * @var string
21
     */
22
    protected $table = 'users';
23
24
    /**
25
     * The attributes that are not mass assignable.
26
     *
27
     * @var array
28
     */
29
    protected $guarded = ['id'];
30
31
    /**
32
     * The attributes that are mass assignable.
33
     *
34
     * @var array
35
     */
36
    protected $fillable = [
37
        'name',
38
        'first_name',
39
        'last_name',
40
        'email',
41
        'password',
42
        'activated',
43
        'token',
44
        'signup_ip_address',
45
        'signup_confirmation_ip_address',
46
        'signup_sm_ip_address',
47
        'admin_ip_address',
48
        'updated_ip_address',
49
        'deleted_ip_address',
50
    ];
51
52
    /**
53
     * The attributes that should be hidden for arrays.
54
     *
55
     * @var array
56
     */
57
    protected $hidden = [
58
        'password',
59
        'remember_token',
60
        'activated',
61
        'token',
62
    ];
63
64
    protected $dates = [
65
        'deleted_at',
66
    ];
67
68
    /**
69
     * Build Social Relationships.
70
     *
71
     * @var array
72
     */
73
    public function social()
74
    {
75
        return $this->hasMany('App\Models\Social');
76
    }
77
78
    /**
79
     * User Profile Relationships.
80
     *
81
     * @var array
82
     */
83
    public function profile()
84
    {
85
        return $this->hasOne('App\Models\Profile');
86
    }
87
88
    // User Profile Setup - SHould move these to a trait or interface...
89
90
    public function profiles()
91
    {
92
        return $this->belongsToMany('App\Models\Profile')->withTimestamps();
93
    }
94
95
    public function hasProfile($name)
96
    {
97
        foreach ($this->profiles as $profile) {
98
            if ($profile->name == $name) {
99
                return true;
100
            }
101
        }
102
103
        return false;
104
    }
105
106
    public function assignProfile($profile)
107
    {
108
        return $this->profiles()->attach($profile);
109
    }
110
111
    public function removeProfile($profile)
112
    {
113
        return $this->profiles()->detach($profile);
114
    }
115
}
116