medialibrary-helper/tests/Models/Post.php

40 lines
1.1 KiB
PHP

<?php
namespace Zoomyboy\MedialibraryHelper\Tests\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class Post extends Model implements HasMedia
{
use InteractsWithMedia;
public $guarded = [];
public function registerMediaCollections(): void
{
$this->addMediaCollection('defaultSingleFile')->singleFile();
$this->addMediaCollection('images');
$this->addMediaCollection('singleForced')->singleFile()->forceFileName(function($adder, $name) {
return $name.' '.now()->format('Y-m-d');
});
$this->addMediaCollection('multipleForced')->forceFileName(function($adder, $name) {
return $name.' '.now()->format('Y-m-d');
});
$this->addMediaCollection('singleStoringHook')->singleFile()->storing(function($adder, $fileName) {
return $adder->withCustomProperties([
'use' => 'AAA',
'ttt' => pathinfo($fileName, PATHINFO_FILENAME),
]);
});
}
}