Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace App\Models;
- use Illuminate\Auth\Authenticatable;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Auth\Passwords\CanResetPassword;
- use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
- use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
- class User extends Model implements AuthenticatableContract, CanResetPasswordContract
- {
- use Authenticatable, CanResetPassword;
- /**
- * The database table used by the model.
- *
- * @var string
- */
- protected $table = 'users';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = ['name', 'email', 'password'];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = ['password', 'remember_token'];
- public static $rules = [
- 'first_name' => 'required',
- 'last_name' => 'required',
- 'email' => 'required|email|unique:users',
- 'password' => 'required|min:6|max:20',
- 'password_confirmation' => 'required|same:password'
- ];
- public static $messages = [
- 'first_name.required' => 'First Name is required',
- 'last_name.required' => 'Last Name is required',
- 'email.required' => 'Email is required',
- 'email.email' => 'Email is invalid',
- 'password.required' => 'Password is required',
- 'password.min' => 'Password needs to have at least 6 characters',
- 'password.max' => 'Password maximum length is 20 characters'
- ];
- public function roles()
- {
- return $this->belongsToMany('App\Models\Role')->withTimestamps();
- }
- public function hasRole($name)
- {
- foreach($this->roles as $role)
- {
- if($role->name == $name) return true;
- }
- return false;
- }
- public function assignRole($role)
- {
- return $this->roles()->attach($role);
- }
- public function removeRole($role)
- {
- return $this->roles()->detach($role);
- }
- public function social()
- {
- return $this->hasMany('App\Models\Social');
- }
- public function addresses()
- {
- return $this->belongsToMany('App\Models\Address');
- }
- public function isAdmin(){
- if( $this->role_id == 4){
- return True;
- }
- return False;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement