lundi 8 juillet 2019

One color multiple image save in Laravel from grid

I have a form in table grid where enter color then click add to grid and then in grid i can add multiple images by specific color. here in this image html view: Html page view

Here is my html code:

    <div class="form-group">
        <div class="col-sm-10">
            <input type="text" class="form-control" id="ColorName" placeholder="Enter Color Name">
        </div>
        <div class="col-sm-2">
            <input type="submit" class="btn btn-success" id="txtcanChangePrice" value="ADD">
        </div>
    </div>

    <div class="form-group ">
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th class="text-center">Color</th>
                    <th class="text-center">Image</th>                
                    <th class="text-center">Action</th>
                </tr>
            </thead>
            <tbody class="text-center" id="tbody">
                <tr>
                    <td class="col-sm-3"><input type="text" name="color1[]" class="form-control"></td>
                    <td class="col-sm-9"><input type="file" name="images1[]" class="form-control" multiple></td>
                    <td class="col-sm-1"><a href="javascript:;" class="deleteRow"><span class="glyphicon glyphicon-trash"></span></a></td>
                </tr>
                <tr>
                    <td class="col-sm-6"><input type="text" name="color2[]" class="form-control"></td>
                    <td class="col-sm-2"><input type="file" name="images2[]" class="form-control" multiple></td>
                    <td class="col-sm-1"><a href="javascript:;" class="deleteRow"><span class="glyphicon glyphicon-trash"></span></a></td>
                </tr>
            </tbody>
        </table>
    </div>

In my controller code:

    foreach ($request->image1 as $images) {
        foreach ($images as $key => $image) {
            $image = $request->file('files')[$key];
            $image->move('uploads/product/', $image->getClientOriginalName());

            $data = new Image();
            $data->color_id = $request->color1[$key];
            $data->image = $image->getClientOriginalName();
            $data->save();
        }
    }

in my controller i tried to get first one for testing purpose only. But image not save. By the way i want save all images by color to database from grid. here is my database view: enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire