Guest User

Untitled

a guest
Jan 13th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Notifications\Notifiable;
  6. use Illuminate\Foundation\Auth\User as Authenticatable;
  7.  
  8. class User extends Authenticatable
  9. {
  10. use Notifiable;
  11.  
  12. /**
  13. * The attributes that are mass assignable.
  14. *
  15. * @var array
  16. */
  17. protected $fillable = [
  18. 'name', 'email', 'password',
  19. ];
  20.  
  21. /**
  22. * The attributes that should be hidden for arrays.
  23. *
  24. * @var array
  25. */
  26. protected $hidden = [
  27. 'password', 'remember_token',
  28. ];
  29.  
  30. /**
  31. * Checks if user is a super admin
  32. *
  33. * @return boolean
  34. */
  35. public function isSuperAdmin() : bool
  36. {
  37. return (bool) $this->is_super_admin;
  38. }
  39.  
  40. /**
  41. * Create admin.
  42. *
  43. * @param array $details
  44. * @return array
  45. */
  46. public function createSuperAdmin(array $details) : self
  47. {
  48. $user = new self($details);
  49.  
  50. if (! $this->superAdminExists()) {
  51. $user->is_super_admin = 1;
  52. }
  53.  
  54. $user->save();
  55.  
  56. return $user;
  57. }
  58.  
  59. /**
  60. * Checks if super admin exists
  61. *
  62. * @return integer
  63. */
  64. public function superAdminExists() : int
  65. {
  66. return self::where('is_super_admin', 1)->count();
  67. }
  68. }
Add Comment
Please, Sign In to add comment