Skip to content

Instantly share code, notes, and snippets.

@yooouuri
Created January 30, 2017 15:39
Show Gist options
  • Select an option

  • Save yooouuri/d3339c266b1d2f87c20bb0df019a62f9 to your computer and use it in GitHub Desktop.

Select an option

Save yooouuri/d3339c266b1d2f87c20bb0df019a62f9 to your computer and use it in GitHub Desktop.
<?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