Add method to get image with parent for article
This commit is contained in:
@@ -44,7 +44,8 @@ class ArticlesDataTable extends DataTable
|
|||||||
{
|
{
|
||||||
$datatables
|
$datatables
|
||||||
->editColumn('thumb', function (Article $article) {
|
->editColumn('thumb', function (Article $article) {
|
||||||
return '<img src="' . Articles::getThumbSrc($article->image) . '">';
|
$image = Articles::getFullImageByArticle($article);
|
||||||
|
return '<img src="' . Articles::getThumbSrc($image) . '">';
|
||||||
})
|
})
|
||||||
->editColumn('article_nature.name', function (Article $article) {
|
->editColumn('article_nature.name', function (Article $article) {
|
||||||
return $article->article_nature ? $article->article_nature->name : '';
|
return $article->article_nature ? $article->article_nature->name : '';
|
||||||
|
|||||||
@@ -80,8 +80,9 @@ class Articles
|
|||||||
$article = self::get($id);
|
$article = self::get($id);
|
||||||
$data = $article->toArray();
|
$data = $article->toArray();
|
||||||
$data['description'] = (!empty($article->description)) ? $article->description : $article->product->description;
|
$data['description'] = (!empty($article->description)) ? $article->description : $article->product->description;
|
||||||
$data['image'] = self::getPreview($article->image);
|
$image = self::getFullImageByArticle($article);
|
||||||
$data['image_big'] = self::getImage($article->image);
|
$data['image'] = self::getPreview($image);
|
||||||
|
$data['image_big'] = self::getImage($image);
|
||||||
$data['inherited'] = self::getInherited($id);
|
$data['inherited'] = self::getInherited($id);
|
||||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||||
$data['tags'] = self::getTagsSlugByArticle($article);
|
$data['tags'] = self::getTagsSlugByArticle($article);
|
||||||
@@ -113,7 +114,7 @@ class Articles
|
|||||||
if (!is_array($data[$article->name] ?? false)) {
|
if (!is_array($data[$article->name] ?? false)) {
|
||||||
$data[$article->name] = [
|
$data[$article->name] = [
|
||||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
||||||
'image' => $article->image,
|
'image' => self::getFullImageByArticle($article),
|
||||||
'product_type' => $article->product_type,
|
'product_type' => $article->product_type,
|
||||||
'product_id' => $article->product_id,
|
'product_id' => $article->product_id,
|
||||||
'product_name' => $article->product->name,
|
'product_name' => $article->product->name,
|
||||||
@@ -324,6 +325,34 @@ class Articles
|
|||||||
return Article::find($id);
|
return Article::find($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getFullImageById($id)
|
||||||
|
{
|
||||||
|
$article = self::get($id);
|
||||||
|
return self::getFullImageByImage($article);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFullImageByArticle($article)
|
||||||
|
{
|
||||||
|
$image = $article->image;
|
||||||
|
if (!$image) {
|
||||||
|
switch ($article->product_type) {
|
||||||
|
case 'App\Models\Botanic\Variety':
|
||||||
|
$variety = $article->product;
|
||||||
|
$image = $variety->image;
|
||||||
|
if (!$image) {
|
||||||
|
$specie = $variety->specie;
|
||||||
|
$image = $specie->image;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'App\Models\Botanic\Specie':
|
||||||
|
$specie = $article->product;
|
||||||
|
$image = $specie->image;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
public static function storeFull($data)
|
public static function storeFull($data)
|
||||||
{
|
{
|
||||||
$images = isset($data['images']) ? $data['images'] : false;
|
$images = isset($data['images']) ? $data['images'] : false;
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ class Offers
|
|||||||
|
|
||||||
public static function getThumbSrc(Offer $offer)
|
public static function getThumbSrc(Offer $offer)
|
||||||
{
|
{
|
||||||
return $offer->article ? Articles::getThumbSrc($offer->article->image) : false;
|
$image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false;
|
||||||
|
return $image ? Articles::getThumbSrc($image) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getLast()
|
public static function getLast()
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ use App\Repositories\Core\Medias;
|
|||||||
|
|
||||||
trait Imageable
|
trait Imageable
|
||||||
{
|
{
|
||||||
public static function storeImages($variety, $files)
|
public static function storeImages($model, $files)
|
||||||
{
|
{
|
||||||
return Medias::storeImages($variety, $files);
|
return Medias::storeImages($model, $files);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getImages($id)
|
public static function getImages($id)
|
||||||
|
|||||||
Reference in New Issue
Block a user