Skip to content
Advertisement

How to get file input name in Laravel?

I am using a jQuery form builder to create any kind of form input. The issue I had, in particular, is when I create multiple file inputs, the input name is generated randomly by default, the format is something like “file-0000-0”. I would like to get the input name but since it’s random, I can only think of one way to fetch the name which is by using the allFiles() method. How do I fetch the name of the input?

Code Example

JavaScript

It will return something like this:

JavaScript

Now how do I get both of the file input names above? Thanks for the help.

Advertisement

Answer

Since allFiles() returns associative array you can get keys:

JavaScript

Or you can loop through that array and access files as well:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement