journal-intime/app/User.php

76 lines
1.8 KiB
PHP
Raw Permalink 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 Illuminate\Support\Facades\Log;
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',
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
/**
* @return string
2019-09-18 16:50:01 +02:00
*/
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(100)
->height(100)
->optimize();
$this->addMediaConversion('icon')
->width(32)
->height(32)
->optimize();
} catch (InvalidManipulation $e) {
Log::alert(sprintf('Error while manipulating Avatar for %s (%s)', $this->email, $e->getMessage()));
}
}
2019-09-18 16:50:01 +02:00
}