1. Go to this page and download the library: Download awcodes/filament-curator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Awcodes\Curator\Models\Media;
public function featuredImage(): BelongsTo
{
return $this->belongsTo(Media::class, 'featured_image_id', 'id');
}
CuratorPicker::make('product_picture_ids')
->multiple()
->relationship('product_pictures', 'id')
->orderColumn('order'), // only necessary if you need to rename the order column
use Awcodes\Curator\Models\Media;
public function productPictures(): BelongsToMany
{
return $this
->belongsToMany(Media::class, 'media_post', 'post_id', 'media_id')
->withPivot('order')
->orderBy('order');
}
public function media(): MorphMany
{
return $this->morphMany(MediaItem::class, 'mediable')->orderBy('order');
}
CuratorPicker::make('document_ids')
->multiple()
->relationship('media', 'id')
->orderColumn('order') // Optional: Rename the order column if needed
->typeColumn('type') // Optional: Rename the type column if needed
->typeValue('document'); // Optional: Specify the type value if using types
use Awcodes\Curator\View\Components\CuratorPicker;
use Awcodes\Curator\PathGenerators\DatePathGenerator;
public function register()
{
CuratorPicker::make('image')
->pathGenerator(DatePathGenerator::class);
}
use Awcodes\Curator\PathGenerators;
class CustomPathGenerator implements PathGenerator
{
public function getPath(?string $baseDir = null): string
{
return ($baseDir ? $baseDir . '/' : '') . 'my/custom/path';
}
}
protected function getTableQuery(): Builder
{
return parent::getTableQuery()->with(['featured_image', 'product_pictures']);
}
use Awcodes\Curator\Curations\CurationPreset;
class ThumbnailPreset extends CurationPreset
{
public function getKey(): string
{
return 'thumbnail';
}
public function getLabel(): string
{
return 'Thumbnail';
}
public function getWidth(): int
{
return 200;
}
public function getHeight(): int
{
return 200;
}
public function getFormat(): string
{
return 'webp';
}
public function getQuality(): int
{
return 60;
}
}
use Awcodes\Curator\Glide\GliderFallback;
class MyCustomGliderFallback extends GliderFallback
{
public function getAlt(): string
{
return 'boring fallback image';
}
public function getHeight(): int
{
return 640;
}
public function getKey(): string
{
return 'card_fallback';
}
public function getSource(): string
{
return 'https://via.placeholder.com/640x420.jpg';
}
public function getType(): string
{
return 'image/jpg';
}
public function getWidth(): int
{
return 420;
}
}