0

I am able to upload all other field values but not images.

My View:

Hobby 1

<input name="hobby[]" placeholder="Hobby1" type="text">
<input type="file" name="hobby_img[]">
<button>Add New Hobby</button>

Controller

public function store(Request $request, Hobby $hobbies)
for ($i=0; $i < count(request('hobby')); ++$i) 
        {
        $hobbies = new Hobby;
        $hobbies->hobby = request('hobby')[$i];

        $images = $request->file('hobby_img');
        $hob_img = uniqid() . '.' .$images[$key]->getClientOriginalExtension();
        $images[$i]->move(public_path('/assets/images/'), $hob_img);
        $hobbies->hobby_img = $hobby_img[$i];
        $hobbies->save();
        }

But it says

The file xxxx.jpg" was not uploaded due to an unknown error.

universal
  • 467
  • 3
  • 12
  • 30
  • What's the code of your form tag? Have you added the "enctype='multipart/form-data'" attribute? (https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean) – Ofir Baruch Nov 19 '17 at 11:49
  • Yes obviously. My form code `
    `
    – universal Nov 20 '17 at 04:19

0 Answers0