Skip to content

Instantly share code, notes, and snippets.

@elinardo10
Created March 28, 2019 23:47
Show Gist options
  • Save elinardo10/4331e7b4f4f464d0b1ad40d820af4fd0 to your computer and use it in GitHub Desktop.
Save elinardo10/4331e7b4f4f464d0b1ad40d820af4fd0 to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Support\Facades\Storage;
use App\Notifications\ResetPassword as ResetPasswordNotification;
use Carbon\Carbon;
use App\Models\Specialty;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'lastname',
'email',
'password',
'birth',
'phone',
'cpf',
'type',
'estado',
'cidade',
'logradouro',
'numero',
'bairro',
'complemento',
'cep',
'specialty_id',
'gender'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $with = ['specialties']; //passando a relação para o user logado no UserPerfil.vue
protected $hidden = [
'password', 'remember_token',
];
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
public function getPhotoAttribute($value)
{ if ($value) {
return asset('storage/img/users/'.$value);
}
return null;
}
public function specialties()
{
return $this->belongsToMany(Specialty::class);
}
public function assignSpecialty($specialty)
{
return $this->specialties()->save(
Specialty::whereName($specialty)->firstOrFail()
//Specialty:where('specialty_id', $id)->get();
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment