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;
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'name', 'email', 'password',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
'password', 'remember_token',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
];
|
2020-03-05 17:40:24 +01:00
|
|
|
|
|
|
|
public function getFolder()
|
|
|
|
{
|
|
|
|
$arrayHash = str_split(strtolower(md5($this->id)));
|
|
|
|
return sprintf('%s/%s', $arrayHash[0], $arrayHash[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getImageData(Post $post)
|
|
|
|
{
|
|
|
|
if (empty($post->image)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = sprintf('%s/%s/%s', storage_path('app'), $this->getFolder(), $post->image);
|
|
|
|
|
|
|
|
if (!is_readable($path)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$type = pathinfo($path, PATHINFO_EXTENSION);
|
|
|
|
$data = file_get_contents($path);
|
|
|
|
return sprintf('data:image/%s;base64,%s', $type, base64_encode($data));
|
|
|
|
}
|
2019-09-18 16:50:01 +02:00
|
|
|
}
|