journal-intime/app/User.php
Clement Desmidt f97c6a56ec Permet la mise à jour du profil
La mise à jour de l'avatar fonctionne à moitié
Pour #12
2020-03-17 17:33:58 +01:00

84 lines
1.8 KiB
PHP

<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Image\Exceptions\InvalidManipulation;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\Models\Media;
class User extends Authenticatable implements HasMedia
{
use Notifiable, HasMediaTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'notification_hour', 'encrypt_messages', 'avatar',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
protected $dates = [
'created_at', 'updated_at', 'email_verified_at',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
// protected $casts = [
// 'email_verified_at' => 'datetime',
// ];
public function getFolder()
{
$arrayHash = str_split(strtolower(md5($this->id)));
return sprintf('%s/%s', $arrayHash[0], $arrayHash[1]);
}
/**
* @return bool
*/
public function isE2E()
{
return (bool) $this->encrypt_messages;
}
/**
* @param Media|null $media
*/
public function registerMediaConversions(Media $media = null)
{
try {
$this->addMediaConversion('thumb')
->width(50)
->height(50);
} catch (InvalidManipulation $e) {
}
}
/**
* @param string $alias
* @return string
*/
public function getAvatar($alias = 'thumb')
{
return $this->getFirstMediaUrl('avatars');
}
}