Add pathinfo information to default Properties
This commit is contained in:
parent
09919a1c29
commit
4a87b83b5a
|
@ -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,
|
||||
]);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue