add shipping rules
This commit is contained in:
@@ -4,22 +4,23 @@ namespace App\Repositories\Core;
|
||||
|
||||
class Medias
|
||||
{
|
||||
|
||||
public static function getImage($model, $conversion = 'normal', $collection = 'images')
|
||||
{
|
||||
$img = $model->getMedia($collection)->first();
|
||||
|
||||
return $img ? $img->getUrl($conversion) : false;
|
||||
}
|
||||
|
||||
|
||||
public static function getImages($model)
|
||||
{
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
return false;
|
||||
}
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
|
||||
return $model->media;
|
||||
}
|
||||
|
||||
@@ -42,6 +43,7 @@ class Medias
|
||||
public static function deleteImages($model, $collection = 'images')
|
||||
{
|
||||
$ret = $model->clearMediaCollection($collection);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -49,38 +51,41 @@ class Medias
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function buildURL($image, $conversion = '')
|
||||
{
|
||||
return self::getPath($image) . self::getConversion($image, $conversion);
|
||||
return self::getPath($image).self::getConversion($image, $conversion);
|
||||
}
|
||||
|
||||
public static function getPath($image)
|
||||
{
|
||||
$model = basename(str_replace('\\', '/', $image->model_type));
|
||||
return '/storage/' . $model . '/' . $image->collection_name . '/' . $image->id;
|
||||
|
||||
return '/storage/'.$model.'/'.$image->collection_name.'/'.$image->id;
|
||||
}
|
||||
|
||||
public static function getConversion($image, $conversion = '')
|
||||
{
|
||||
// return $conversion ? '/conversions/' . $image->name . '-' . $conversion . self::getExtension($image->file_name) : $image->file_name;
|
||||
return $conversion ? '/conversions/' . $image->name . '-' . $conversion . '.jpg' : $image->file_name;
|
||||
return $conversion ? '/conversions/'.$image->name.'-'.$conversion.'.jpg' : $image->file_name;
|
||||
}
|
||||
|
||||
public static function getExtension($filename)
|
||||
{
|
||||
return '.' . pathinfo($filename, PATHINFO_EXTENSION);
|
||||
return '.'.pathinfo($filename, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
public static function getImageSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
if (! $image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$filename = self::getFilename($image);
|
||||
|
||||
return "/storage/$id/$filename";
|
||||
}
|
||||
|
||||
@@ -101,13 +106,14 @@ class Medias
|
||||
|
||||
public static function getSrcByType($image, $type)
|
||||
{
|
||||
return $image ? '/storage/' . $image['id'] . '/conversions/' . self::getFilename($image, $type) : false;
|
||||
return $image ? '/storage/'.$image['id'].'/conversions/'.self::getFilename($image, $type) : false;
|
||||
}
|
||||
|
||||
public static function getFilename($image, $type = false)
|
||||
{
|
||||
$image['name'] = self::convertName($image['name']);
|
||||
return $image['name'] . ($type ? '-' . $type : '') . self::getExtension($image['file_name']);
|
||||
|
||||
return $image['name'].($type ? '-'.$type : '').self::getExtension($image['file_name']);
|
||||
}
|
||||
|
||||
public static function convertName($name)
|
||||
|
||||
Reference in New Issue
Block a user