<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
use DateTimeInterface;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'phone', 'address', 'nuit', 'picture','bi','club_default_id'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'responsible_name', 'responsible_phone',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/*
* Metodo para criar varias Roles
*/
public function roles(){
return $this->belongsToMany('App\Role');
}
public function club(){
return $this->belongsTo('App\Models\Club','clubs_id');
}
public function posts(){
return $this->hasMany('App\Models\Post','users_id');
}
/*
* Primeiro verifica se existe esta role e a quem pertence
*/
public function hasAnyRoles($roles){
return null !== $this->roles()->whereIn('name', $roles)->first();
}
/*
* Passa uma so role para usuario normal
*/
public function hasAnyRole($role){
return null !== $this->roles()->where('name', $role)->first();
}
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('d-m-Y H:i:s');
}
}