Add preview from father, add new features
This commit is contained in:
56
app/Repositories/Core/Media.php
Normal file
56
app/Repositories/Core/Media.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Media
|
||||
{
|
||||
|
||||
public static function getImages($model) {
|
||||
if ($model) {
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($model, $file)
|
||||
{
|
||||
return $model->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return "1";
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$images = json_decode($image['responsive_images'], true);
|
||||
$urls = $images['medialibrary_original']['urls'];
|
||||
|
||||
$img = $urls[count($urls)-1];
|
||||
$src = "storage/$id/responsive-images/$img";
|
||||
return $src;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user