PHP code example of lisowiecw / filament-media-library
1. Go to this page and download the library: Download lisowiecw/filament-media-library 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/ */
lisowiecw / filament-media-library example snippets
use Lisowiecw\MediaLibrary\MediaLibraryPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugin(MediaLibraryPlugin::make());
}
use Lisowiecw\MediaLibrary\Concerns\HasMedia;
class Article extends Model
{
use HasMedia;
}
use Lisowiecw\MediaLibrary\Forms\Components\MediaPicker;
MediaPicker::make('cover_image')
->visibility('public')
->acceptedFileTypes(['image/*']);
MediaPicker::make('gallery')
->visibility('public')
->multiple()
->reorderable()
->droppable();
$article->firstMedia('cover_image')?->url();
foreach ($article->media('gallery') as $asset) {
echo $asset->url();
}
$products = Product::query()->withMedia('thumbnail')->get();
$products->loadMedia('thumbnail', 'gallery'); // hosts already in memory
$product->loadMedia('thumbnail'); // one host
public function view(?User $user, MediaAsset $asset): bool
{
return $user !== null && Order::forUser($user)->hasUnspentDownloadOf($asset);
}
$article->detachMedia('cover_image', $asset);
use Lisowiecw\MediaLibrary\Exceptions\DeleteBlocked;
use Lisowiecw\MediaLibrary\Lifecycle\AssetLifecycle;
try {
app(AssetLifecycle::class)->delete($asset);
} catch (DeleteBlocked $blocked) {
// $blocked->usage is the list to review, then:
app(AssetLifecycle::class)->delete($asset, force: true);
}