Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

46 changes: 16 additions & 30 deletions src/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,40 +409,26 @@ public static function table(Table $table): Table
->columns([
TextColumn::make('id'),

ImageColumn::make('cover_image')
->stacked()
->label('Image')
->getStateUsing(function (Product $record) {
$url = $record->getFirstMediaUrl('images', 'thumb');

return $url ?: null;
})
ImageColumn::make('images')
->label('Images')
->circular()
->defaultImageUrl(static::getPlaceholderImageUrl())
->extraImgAttributes(function (Product $record) {
$coverMedia = $record->getMedia('images')
->filter(fn ($media) => $media->getCustomProperty('is_cover', false))
->first();
->stacked()
->getStateUsing(function (Product $record): array {
$images = $record->getMedia('images');

if (! $coverMedia) {
$coverMedia = $record->getMedia('images')->first();
if ($images->isEmpty()) {
return [static::getPlaceholderImageUrl()];
}

$fullImageUrl = $coverMedia ? $coverMedia->getUrl() : null;
$imageName = $coverMedia ? json_encode($coverMedia->getCustomProperty('name', [])) : '{}';
$imageDescription = $coverMedia ? json_encode($coverMedia->getCustomProperty('description', [])) : '{}';

return [
'class' => 'cursor-pointer product-image-trigger',
'data-url' => $fullImageUrl ?: static::getPlaceholderImageUrl(),
'data-image-name' => htmlspecialchars($imageName, ENT_QUOTES, 'UTF-8'),
'data-image-description' => htmlspecialchars($imageDescription, ENT_QUOTES, 'UTF-8'),
'data-product-name' => htmlspecialchars(json_encode($record->getTranslations('name')), ENT_QUOTES, 'UTF-8'),
'data-product-code' => $record->code ?: '',
'data-filename' => $coverMedia ? $coverMedia->file_name : '',
'onclick' => 'event.stopPropagation(); return false;',
];
}),
return $images->map(fn ($media) => $media->getUrl())->toArray();
})
->defaultImageUrl(static::getPlaceholderImageUrl())
->preview(fn (Model $record): array => [
'title' => "{$record->name} Product",
'link' => ProductResource::getUrl('edit', [
'record' => $record?->id,
]),
]),

TextColumn::make('name')
->toggleable(false),
Expand Down
6 changes: 0 additions & 6 deletions src/Filament/Resources/ProductResource/Pages/ListProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Filament\Resources\Pages\ListRecords;
use Filament\Resources\Pages\ListRecords\Concerns\Translatable;
use Filament\Support\Enums\MaxWidth;
use Illuminate\Contracts\View\View;

class ListProducts extends ListRecords
{
Expand All @@ -25,9 +24,4 @@ protected function getHeaderActions(): array
Actions\CreateAction::make(),
];
}

public function getFooter(): ?View
{
return view('eclipse-catalogue::filament.resources.product-resource.pages.list-products-footer');
}
}
Loading