vendredi 14 juillet 2017

Laravel Multiple Image upload

I want to upload multiple image for my restaurant site. where I want to add many food item with image. but problem is when i submit with my input it only enter multiple image and only first data of entry to the database again and again with those image respectively. Here is my store method code:

         $id=$restaurant->id;
        $files=$request->file('image');

            foreach ($files as $file) {
           $menu=time().'.'.$file->getClientOriginalName();
     foreach ($request->category_name as $key => $v) {
            $data = array(
                'rest_id'=>$id,
                'cat_id'=>$v,
                'menu_name'=>$request->menu_name [$key],
                'menu_price'=>$request->menu_price[$key],
                'image'=>$menu
                );

                 Mnu::insert($data);
                 break;
     }
     } 
    }

Here is My Html Code:

<tbody>
                                    <tr>
                                        <td>
                                            <select name="category_name[]" class="form-control productname">
                                                <option value="0" selected="true" disabled="true">Food Category</option>
                                                @foreach($category_name as $key =>$p)
                                                <option value="{!! $key !!} ">{!! $p !!}</option>
                                                @endforeach
                                            </select>
                                        </td>
                                        <td> <input type="text" name="menu_name[]"> </td>
                                        <td> <input type="text" name="menu_price[]"> </td>
                                        <td> <input type="file" name="image[]" multiple> </td>
                                        </tr>
                                </tbody>

Here is my Database table: .

Database Here in id 347 and 348 have same data expect image field. but my input was difference . But it take only diffrences images and same data

Please Help me to sort out this problem. pleasee



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire