I am trying to get input value in a nested array like the one showed bellow.But the problem is the image array is missing or if not I don't know how to get the value of the image file.
This is how i want
Array
(
[_token] => 7iSeeTphiVbpQw3iQ8eb1lReMRzxBY8Lt1lKqQea
[food] => Array
(
[product[1] => Array
(
[name] => 1
[price] => 10
[image]=>Uploaded image here
)
)
)
But what i am actually getting is this
Array
(
[_token] => 7iSeeTphiVbpQw3iQ8eb1lReMRzxBY8Lt1lKqQea
[food] => Array
(
[product[1] => Array
(
[name] => 1
[price] => 10
)
[product[2] => Array
(
[name] => 1
[price] => 10
)
)
)
And my form blade is like this
<form method="POST" action="" enctype="multipart/form-data">
{{csrf_field()}}
<!-----PHP LOOP STARTS HERE ---->
<select class="form-control" name="food[product[$i][name]]">
<option value="1">Fried rice</option>
<option value="2">Demo food</option>
</select>
<input type="text" placeholder="set a price" class="form-control" name="food[product[$i][price]]">
<input type="file" placeholder="set a price" class="form-control" name="food[product[$i][image]]">
<!-----PHP LOOP ENDS HERE ---->
<button type='submit'>Submit</button>
Can anyone help me how can i get the image so i can store in folder and save the url to database?? In controller
UPDATE I changed the form
<input type="text" placeholder="set a price" class="form-control" name="product[$i][price]">
<input type="file" placeholder="set a price" class="form-control" name="product[$i][image]">
In reponse i am getting
[product] => Array
(
[1] => Array
(
[name] => 1
[price] => 10
[image] => Illuminate\Http\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => dell-inspiron-3567-notebook-original-imaetu5ch98vzge5.jpeg
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 40705
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[hashName:protected] =>
[pathName:SplFileInfo:private] => C:\xampp\tmp\php17B2.tmp
[fileName:SplFileInfo:private] => php17B2.tmp
)
)
After doing that i can see the image is being uploaded. Now how to capture that image ?? If i try foreach loop that image is getting missing. I am getting undefined index for image. so how shall i proceed ?