journal-intime/app/User.php

84 lines
1.8 KiB
PHP
Raw Normal View History

2019-09-18 16:50:01 +02:00
<?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;
2019-09-18 16:50:01 +02:00
class User extends Authenticatable implements HasMedia
2019-09-18 16:50:01 +02:00
{
use Notifiable, HasMediaTrait;
2019-09-18 16:50:01 +02:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'notification_hour', 'encrypt_messages', 'avatar',
2019-09-18 16:50:01 +02:00
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
protected $dates = [
'created_at', 'updated_at', 'email_verified_at',
];
2019-09-18 16:50:01 +02:00
/**
* 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');
}
2019-09-18 16:50:01 +02:00
}