update filename hook
This commit is contained in:
parent
47c734dfd4
commit
63fb409951
|
@ -65,7 +65,7 @@ class CollectionExtension
|
|||
return;
|
||||
}
|
||||
$this->customCallbacks = collect([
|
||||
'forceFileName' => fn ($name) => $name,
|
||||
'forceFileName' => fn ($model, $name) => $name,
|
||||
'stored' => fn ($event) => true,
|
||||
'storing' => fn ($adder, $name) => $adder,
|
||||
'withDefaultProperties' => fn ($path) => [],
|
||||
|
|
|
@ -45,7 +45,7 @@ class MediaController
|
|||
|
||||
$medias = collect($content)->map(function ($c) use ($collection, $model) {
|
||||
$pathinfo = pathinfo($c['name']);
|
||||
$path = $collection->runCallback('forceFileName', $pathinfo['filename']).'.'.$pathinfo['extension'];
|
||||
$path = $collection->runCallback('forceFileName', $model, $pathinfo['filename']).'.'.$pathinfo['extension'];
|
||||
Storage::disk('public')->put($path, base64_decode($c['content']));
|
||||
$adder = $model
|
||||
->addMedia(Storage::disk('public')->path($path))
|
||||
|
|
|
@ -29,11 +29,11 @@ class Post extends Model implements HasMedia
|
|||
|
||||
$this->addMediaCollection('images');
|
||||
|
||||
$this->addMediaCollection('singleForced')->singleFile()->forceFileName(function ($name) {
|
||||
$this->addMediaCollection('singleForced')->singleFile()->forceFileName(function ($model, $name) {
|
||||
return $name.' '.now()->format('Y-m-d');
|
||||
});
|
||||
|
||||
$this->addMediaCollection('multipleForced')->forceFileName(function ($name) {
|
||||
$this->addMediaCollection('multipleForced')->forceFileName(function ($model, $name) {
|
||||
return $name.' '.now()->format('Y-m-d');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue