Advertisement
Guest User

Untitled

a guest
Dec 26th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <?php namespace App\Models;
  2.  
  3. use Illuminate\Auth\Authenticatable;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Auth\Passwords\CanResetPassword;
  6. use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
  7. use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
  8.  
  9. class User extends Model implements AuthenticatableContract, CanResetPasswordContract
  10. {
  11. use Authenticatable, CanResetPassword;
  12.  
  13. /**
  14. * The database table used by the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'users';
  19.  
  20. /**
  21. * The attributes that are mass assignable.
  22. *
  23. * @var array
  24. */
  25. protected $fillable = ['name', 'email', 'password'];
  26.  
  27. /**
  28. * The attributes excluded from the model's JSON form.
  29. *
  30. * @var array
  31. */
  32. protected $hidden = ['password', 'remember_token'];
  33.  
  34. public static $rules = [
  35. 'first_name' => 'required',
  36. 'last_name' => 'required',
  37. 'email' => 'required|email|unique:users',
  38. 'password' => 'required|min:6|max:20',
  39. 'password_confirmation' => 'required|same:password'
  40. ];
  41.  
  42. public static $messages = [
  43. 'first_name.required' => 'First Name is required',
  44. 'last_name.required' => 'Last Name is required',
  45. 'email.required' => 'Email is required',
  46. 'email.email' => 'Email is invalid',
  47. 'password.required' => 'Password is required',
  48. 'password.min' => 'Password needs to have at least 6 characters',
  49. 'password.max' => 'Password maximum length is 20 characters'
  50. ];
  51.  
  52. public function roles()
  53. {
  54. return $this->belongsToMany('App\Models\Role')->withTimestamps();
  55. }
  56.  
  57. public function hasRole($name)
  58. {
  59. foreach($this->roles as $role)
  60. {
  61. if($role->name == $name) return true;
  62. }
  63.  
  64. return false;
  65. }
  66.  
  67. public function assignRole($role)
  68. {
  69. return $this->roles()->attach($role);
  70. }
  71.  
  72. public function removeRole($role)
  73. {
  74. return $this->roles()->detach($role);
  75. }
  76.  
  77. public function social()
  78. {
  79. return $this->hasMany('App\Models\Social');
  80. }
  81. public function addresses()
  82. {
  83. return $this->belongsToMany('App\Models\Address');
  84. }
  85. public function isAdmin(){
  86. if( $this->role_id == 4){
  87. return True;
  88. }
  89. return False;
  90. }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement