Add preview from father, add new features
This commit is contained in:
@@ -2,12 +2,10 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Media;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Models\Shop\Article;
|
||||
@@ -15,12 +13,6 @@ use App\Models\Shop\Article;
|
||||
class Articles
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Article::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Article::orderBy('name','asc')->get();
|
||||
@@ -28,11 +20,11 @@ class Articles
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Article::with('product')->findOrFail($id);
|
||||
$data = $article->toArray();
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
$data['prices'] = self::getPricesByArticle($article);
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$data['article'] = $article->toArray();
|
||||
$data['article']['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['article']['tags'] = self::getTagsByArticle($article);
|
||||
$data['article']['prices'] = self::getPricesByArticle($article);
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
@@ -53,7 +45,6 @@ class Articles
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
// TODO add category
|
||||
return Article::with(['prices','product','image'])->get();
|
||||
}
|
||||
|
||||
@@ -109,7 +100,7 @@ class Articles
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = Article::find($id);
|
||||
$article = self::get($id);
|
||||
$ret = $article->update($data);
|
||||
return $article;
|
||||
}
|
||||
@@ -133,12 +124,7 @@ class Articles
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->syncTags($tags, true);
|
||||
} else return false;
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
@@ -148,55 +134,27 @@ class Articles
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($article, $file);
|
||||
}
|
||||
}
|
||||
return Media::storeImages($article, $files);
|
||||
}
|
||||
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return $article->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
return Media::storeImage($article, $file);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
if ($article)
|
||||
{
|
||||
$article->getMedia();
|
||||
foreach ($article->media as $key => $media) {
|
||||
$article->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $article->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
|
||||
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;
|
||||
return Media::getThumbSrc($image);
|
||||
}
|
||||
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
$article = self::get($id);
|
||||
$article->getMedia();
|
||||
$ret = $article->media[$index]->delete();
|
||||
return "1";
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user