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
|
public function boot(): void
|
||||||
{
|
{
|
||||||
MediaCollection::mixin(new class() {
|
MediaCollection::mixin(new class()
|
||||||
|
{
|
||||||
public function forceFileName()
|
public function forceFileName()
|
||||||
{
|
{
|
||||||
return fn ($callback) => $this->registerCustomCallback('forceFileName', $callback);
|
return fn ($callback) => $this->registerCustomCallback('forceFileName', $callback);
|
||||||
|
@ -86,7 +87,7 @@ class CollectionExtension
|
||||||
'after' => fn ($event) => true,
|
'after' => fn ($event) => true,
|
||||||
'destroyed' => fn ($event) => true,
|
'destroyed' => fn ($event) => true,
|
||||||
'storing' => fn ($adder, $name) => $adder,
|
'storing' => fn ($adder, $name) => $adder,
|
||||||
'withDefaultProperties' => fn ($path) => [],
|
'withDefaultProperties' => fn ($path, $pathinfo) => [],
|
||||||
'withPropertyValidation' => fn ($path) => [],
|
'withPropertyValidation' => fn ($path) => [],
|
||||||
'withFallback' => fn ($parent) => null,
|
'withFallback' => fn ($parent) => null,
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -54,7 +54,7 @@ class MediaController
|
||||||
$adder = $this->fileAdderFromData($model, $c['content'], $collection)
|
$adder = $this->fileAdderFromData($model, $c['content'], $collection)
|
||||||
->usingName($basename)
|
->usingName($basename)
|
||||||
->usingFileName($path)
|
->usingFileName($path)
|
||||||
->withCustomProperties($collection->runCallback('withDefaultProperties', $path));
|
->withCustomProperties($collection->runCallback('withDefaultProperties', $path, $pathinfo));
|
||||||
|
|
||||||
return tap(
|
return tap(
|
||||||
$collection->runCallback('storing', $adder, $path)->toMediaCollection($collection->name),
|
$collection->runCallback('storing', $adder, $path)->toMediaCollection($collection->name),
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Post extends Model implements HasMedia
|
||||||
Event::dispatch(new MediaStored($media));
|
Event::dispatch(new MediaStored($media));
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path) => [
|
$this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path, $pathinfo) => [
|
||||||
'test' => Str::camel($path),
|
'test' => Str::camel($path),
|
||||||
])->withPropertyValidation(fn ($path) => [
|
])->withPropertyValidation(fn ($path) => [
|
||||||
'test' => 'string|max:10',
|
'test' => 'string|max:10',
|
||||||
|
|
Loading…
Reference in New Issue