22
app/User.php
22
app/User.php
@@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user