Add pathinfo information to default Properties

This commit is contained in:
philipp lang 2024-10-30 15:25:43 +01:00
parent 09919a1c29
commit 4a87b83b5a
3 changed files with 5 additions and 4 deletions

View File

@ -8,7 +8,8 @@ class CollectionExtension
{
public function boot(): void
{
MediaCollection::mixin(new class() {
MediaCollection::mixin(new class()
{
public function forceFileName()
{
return fn ($callback) => $this->registerCustomCallback('forceFileName', $callback);
@ -86,7 +87,7 @@ class CollectionExtension
'after' => fn ($event) => true,
'destroyed' => fn ($event) => true,
'storing' => fn ($adder, $name) => $adder,
'withDefaultProperties' => fn ($path) => [],
'withDefaultProperties' => fn ($path, $pathinfo) => [],
'withPropertyValidation' => fn ($path) => [],
'withFallback' => fn ($parent) => null,
]);

View File

@ -54,7 +54,7 @@ class MediaController
$adder = $this->fileAdderFromData($model, $c['content'], $collection)
->usingName($basename)
->usingFileName($path)
->withCustomProperties($collection->runCallback('withDefaultProperties', $path));
->withCustomProperties($collection->runCallback('withDefaultProperties', $path, $pathinfo));
return tap(
$collection->runCallback('storing', $adder, $path)->toMediaCollection($collection->name),

View File

@ -56,7 +56,7 @@ class Post extends Model implements HasMedia
Event::dispatch(new MediaStored($media));
});
$this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path) => [
$this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path, $pathinfo) => [
'test' => Str::camel($path),
])->withPropertyValidation(fn ($path) => [
'test' => 'string|max:10',