Created
January 30, 2017 15:39
-
-
Save yooouuri/d3339c266b1d2f87c20bb0df019a62f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App; | |
| use Illuminate\Notifications\Notifiable; | |
| use Illuminate\Foundation\Auth\User as Authenticatable; | |
| class User extends Authenticatable | |
| { | |
| use Notifiable; | |
| protected $table = 'users'; | |
| /** | |
| * The attributes that are mass assignable. | |
| * | |
| * @var array | |
| */ | |
| protected $fillable = [ | |
| 'name', 'email', 'password', | |
| ]; | |
| /** | |
| * The attributes that should be hidden for arrays. | |
| * | |
| * @var array | |
| */ | |
| protected $hidden = [ | |
| 'password', 'remember_token', 'role_id', | |
| ]; | |
| protected $appends = [ | |
| 'role', | |
| ]; | |
| public function getRoleAttribute() | |
| { | |
| return $this->role->name; | |
| } | |
| /** | |
| * Country where the user lives in. | |
| * | |
| * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |
| */ | |
| public function country() | |
| { | |
| return $this->belongsTo('App\Country'); | |
| } | |
| /** | |
| * User role. | |
| * | |
| * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | |
| */ | |
| public function role() | |
| { | |
| return $this->belongsTo('App\Role'); | |
| } | |
| /** | |
| * Check if the user is an admin. | |
| * | |
| * @return bool | |
| */ | |
| public function isAdmin() | |
| { | |
| if ($this->role->name == 'admin') { | |
| return true; | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment