No Description

User.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App;
  3. use Illuminate\Notifications\Notifiable;
  4. use Illuminate\Contracts\Auth\MustVerifyEmail;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. class User extends Authenticatable
  7. {
  8. use Notifiable;
  9. /**
  10. * The attributes that are mass assignable.
  11. *
  12. * @var array
  13. */
  14. protected $fillable = [
  15. 'name', 'email', 'password', 'google_id', 'added_by',
  16. ];
  17. /**
  18. * The attributes that should be hidden for arrays.
  19. *
  20. * @var array
  21. */
  22. protected $hidden = [
  23. 'password', 'remember_token', 'google_id',
  24. ];
  25. /**
  26. * The attributes that should be cast to native types.
  27. *
  28. * @var array
  29. */
  30. protected $casts = [
  31. 'email_verified_at' => 'datetime',
  32. ];
  33. public function permissions() {
  34. return $this->hasMany(Permission::class);
  35. }
  36. public function departments() {
  37. return $this->belongsToMany(Department::class, 'permissions', 'user_id', 'division_id')->wherePivot('level', '=', 1);
  38. }
  39. public function faculties() {
  40. return $this->belongsToMany(Faculty::class, 'permissions', 'user_id', 'division_id')->wherePivot('level', '=', 2);
  41. }
  42. public function getIsAdminAttribute() {
  43. return $this->permissions->where('level', '=', 3)->isNotEmpty();
  44. }
  45. }