Looks like you need a foreach loop: $file[0], $file[1], etc
Something like:
foreach ($files as $file) {
// rest of code
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone, so i am having difficulty with returning multiple uploaded image url to my filament form FileUpload Input Field using the getUploadedFileUsing() method. See below for my code and further explanation.
Forms\Components\Select::make('task_id')
->options(Task::all()->pluck('name', 'id'))
->required()
->disabled()
->reactive(),
Forms\Components\FileUpload::make('evidence')
->label('View Submitted Evidence')
->disk('do')
->multiple()
->disabled()
->getUploadedFileUsing(function ($state){
if ($state && is_array($state)) {
//debug return value for $state: dd($state);
$file = [];
foreach ($state as $url) {
if($url['url']){
$file[] = $url['url'];
}
}
//debug return value for files dd($file);
return $file;
}
return [];
})
->afterStateHydrated(function (callable $set, $get){
$task_id = Task::find($get('task_id'));
$evidence = $task_id->evidence;
if ($task_id && $evidence) {
$decodedUrl = json_decode($evidence, true);
if (isset($decodedUrl['urls']) && is_array($decodedUrl['urls'])) {
$formattedEvidence = collect($decodedUrl['urls'])->map( function ($item){
return [
'url' => $item['url'],
'name' => basename($item['url']),
];
})->toArray();
$set('evidence', $formattedEvidence);
Log::info('Formatted Evidence Urls', $set('evidence', $formattedEvidence));
}else{
$set('evidence', []);
Log::warning('Evidence not found for ID:', ['task_id' => $task_id]);
}
}else{
$set('evidence', []);
}
}),
The intent is to fetch the url data stored on the 'evidence' column of the Task table which are inserted as json data from the frontend using standard Laravel save(). Note i am using Filament form to manage the backend where i getting this issue. See below for the Dump and Die Debugs
dd($state) returns
array:2 [
0 => array:2 [
"url" =>"https://adeptigo.lon1.digitaloceanspaces.com/learner_files/Ofure%20Igbelos/Task%201/DSvWUD98ZdracOS791lZXvZhRyRgYnIJ4w8aBA47.jpg"
"name" => "DSvWUD98ZdracOS791lZXvZhRyRgYnIJ4w8aBA47.jpg"
]
1 => array:2 [
"url" => "https://adeptigo.lon1.digitaloceanspaces.com/learner_files/Ofure%20Igbelos/Task%201/r86u2OP0fpiysPqoh5BmL9S7XQSedSTQ9tzZ24kO.jpg"
"name" => "r86u2OP0fpiysPqoh5BmL9S7XQSedSTQ9tzZ24kO.jpg"
]
]
While dd($file); returns;
array:2 [
0 => "https://adeptigo.lon1.digitaloceanspaces.com/learner_files/Ofure%20Igbelos/Task%201/DSvWUD98ZdracOS791lZXvZhRyRgYnIJ4w8aBA47.jpg"
1 =>"https://adeptigo.lon1.digitaloceanspaces.com/learner_files/Ofure%20Igbelos/Task%201/r86u2OP0fpiysPqoh5BmL9S7XQSedSTQ9tzZ24kO.jpg"]
Now this appears on the filament form view as [object Object] rather than the actual files.
Also, a different approach has been to pass the the $url directly to a $file variable like this;
foreach ($state as $url) {
if($url['url']){
$file = $url;
}
}
//dd($file);
return $file;
This works but only returns the last item in the array and duplicates the image on view twice. See below for the Dump and Die returned for $file in this approach
array:2 [
"url" => "https://adeptigo.lon1.digitaloceanspaces.com/learner_files/Ofure%20Igbelos/Task%201/r86u2OP0fpiysPqoh5BmL9S7XQSedSTQ9tzZ24kO.jpg"
"name" => "r86u2OP0fpiysPqoh5BmL9S7XQSedSTQ9tzZ24kO.jpg"
]
Please or to participate in this conversation.