PHP code example of apimediaru / nova-media-library
1. Go to this page and download the library: Download apimediaru/nova-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/ */
apimediaru / nova-media-library example snippets
use APIMedia\NovaMediaLibrary\Http\Services\MediaLibraryService;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\HasMedia;
use Spatie\Image\Manipulations;
class ExampleModel extends Model implements HasMedia
{
use InteractsWithMedia;
/**
* Register media collections
*/
public function registerMediaCollections(): void
{
$this->addMediaCollection('gallery');
}
/**
* Register media conversions
*
* @throws \Spatie\Image\Exceptions\InvalidManipulation
*/
public function registerMediaConversions(Media $media = null): void
{
// Adds 'thumbnail' conversions attached to all collections
MediaLibraryService::addLibraryConversions($this);
$this->addMediaConversion('thumb')
->fit(Manipulations::FIT_CROP, 150, 150)
->performOnCollections('gallery');
$this->addMediaConversion('medium')
->fit(Manipulations::FIT_MAX, 720, 720)
->performOnCollections('gallery');
$this->addMediaConversion('large')
->fit(Manipulations::FIT_MAX, 1920, 1920)
->performOnCollections('gallery');
}
}
public function fields(Request $request)
{
return [
// ...
MediaField::make(__('gallery'), 'gallery')
->limit(10),
];
}
public function fields(Request $request)
{
return [
// ...
MediaField::make(__('gallery'), 'gallery')
->checkDuplicates(false),
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.