5 use Illuminate\Auth\Authenticatable;
6 use Illuminate\Database\Eloquent\Model;
7 use Illuminate\Auth\Passwords\CanResetPassword;
8 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9 use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
11 class User extends Model implements AuthenticatableContract, CanResetPasswordContract
13 use Authenticatable, CanResetPassword;
16 * The database table used by the model.
20 protected $table = 'users';
23 * The attributes that are mass assignable.
27 protected $fillable = ['name', 'email'];
30 * The attributes excluded from the model's JSON form.
34 protected $hidden = ['password', 'remember_token'];
37 * Returns a default guest user.
39 public static function getDefault()
48 * Permissions and roles
52 * The roles that belong to the user.
54 public function roles()
56 return $this->belongsToMany('Oxbow\Role');
59 public function getRoleAttribute()
61 return $this->roles()->first();
65 * Check if the user has a particular permission.
66 * @param $permissionName
69 public function can($permissionName)
71 $permissions = $this->role->permissions()->get();
72 $permissionSearch = $permissions->search(function ($item, $key) use ($permissionName) {
73 return $item->name == $permissionName;
75 return $permissionSearch !== false;
79 * Attach a role to this user.
82 public function attachRole(Role $role)
84 $this->attachRoleId($role->id);
88 * Attach a role id to this user.
91 public function attachRoleId($id)
93 $this->roles()->sync([$id]);
97 * Returns the user's avatar,
98 * Uses Gravatar as the avatar service.
103 public function getAvatar($size = 50)
105 $emailHash = md5(strtolower(trim($this->email)));
106 return '//www.gravatar.com/avatar/' . $emailHash . '?s=' . $size . '&d=identicon';