Skip to content

Commit 5338987

Browse files
authored
Merge pull request #17611 from grokability/#9965-fallback-to-category-image-for-consumables
Fixed #9965 - fallback to category images (f there are any) when no c…
2 parents 3d95808 + 3b243b3 commit 5338987

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/Http/Transformers/ConsumablesTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function transformConsumable(Consumable $consumable)
2525
$array = [
2626
'id' => (int) $consumable->id,
2727
'name' => e($consumable->name),
28-
'image' => ($consumable->image) ? Storage::disk('public')->url('consumables/'.e($consumable->image)) : null,
28+
'image' => ($consumable->getImageUrl()) ? ($consumable->getImageUrl()) : null,
2929
'category' => ($consumable->category) ? ['id' => $consumable->category->id, 'name' => e($consumable->category->name)] : null,
3030
'company' => ($consumable->company) ? ['id' => (int) $consumable->company->id, 'name' => e($consumable->company->name)] : null,
3131
'item_no' => e($consumable->item_no),

app/Models/Consumable.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,16 @@ public function assetlog()
230230
*/
231231
public function getImageUrl()
232232
{
233+
// If there is a consumable image, use that
233234
if ($this->image) {
234235
return Storage::disk('public')->url(app('consumables_upload_path').$this->image);
236+
237+
// Otherwise check for a category image
238+
} elseif (($this->category) && ($this->category->image)) {
239+
return Storage::disk('public')->url(app('categories_upload_path').e($this->category->image));
235240
}
236-
return false;
237241

242+
return false;
238243
}
239244

240245
/**

0 commit comments

Comments
 (0)