Ajoute la gestion primaire des images

Pour #4
This commit is contained in:
2020-03-05 17:40:24 +01:00
parent 9a30d17fe0
commit ac5afa42e3
5 changed files with 99 additions and 7 deletions

View File

@@ -36,4 +36,26 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
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));
}
}