Chronyms /
Qitsune
| 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
Loading history...
|
|||
| 14 | use Notifiable; |
||
|
0 ignored issues
–
show
|
|||
| 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 | 'scout_name', |
||
| 38 | 'first_name', |
||
| 39 | 'last_name', |
||
| 40 | 'name_gen', |
||
| 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 | * User Profile Relationships. |
||
| 70 | * |
||
| 71 | * @var array |
||
| 72 | * |
||
| 73 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
| 74 | */ |
||
| 75 | public function profile() |
||
| 76 | { |
||
| 77 | return $this->hasOne('App\Models\Profile'); |
||
| 78 | } |
||
| 79 | |||
| 80 | // User Profile Setup - SHould move these to a trait or interface... |
||
| 81 | |||
| 82 | public function profiles() |
||
| 83 | { |
||
| 84 | return $this->belongsToMany('App\Models\Profile')->withTimestamps(); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function hasProfile($name_gen) |
||
| 88 | { |
||
| 89 | foreach ($this->profiles as $profile) { |
||
| 90 | if ($profile->name_gen == $name_gen) { |
||
| 91 | return true; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | return false; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function assignProfile($profile) |
||
| 99 | { |
||
| 100 | return $this->profiles()->attach($profile); |
||
| 101 | } |
||
| 102 | |||
| 103 | public function removeProfile($profile) |
||
| 104 | { |
||
| 105 | return $this->profiles()->detach($profile); |
||
| 106 | } |
||
| 107 | } |
||
| 108 |