Add multiple media to a collection #3295
Unanswered
chinmaypurav
asked this question in
Q&A
Replies: 2 comments
-
This is a solution I am using for now private function getDottedKeysArray(array $array, string $baseKey): array
{
return array_keys(Arr::dot($array, "{$baseKey}."));
}
private function addMutipleFilesFromRequest(Model $model, array $keys, string $collection = 'default'): void
{
foreach ($keys as $key) {
$model->addMediaFromRequest($key)
->toMediaCollection($collection);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I too was struggling with this just recently and the solution I settled on was as below. $model->addMultipleMediaFromRequest(['avatars'])
->each(function (FileAdder $fileAdder) {
$fileAdder->toMediaCollection();
}); This was inspired by the test suite for the package. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a file input that accepts
n
files. I am usingmultiple
attribute to accept thatn
file input.I get an array of
UploadedFile
instances.If it's a single file I can do
But how do I do it dynamically for
n
files?I need an efficient way to handle this situation.
If there is not any way, I am willing to open a PR for the same.
Beta Was this translation helpful? Give feedback.
All reactions