mardi 10 septembre 2019

Make an array of colors and images

I'm using laravel and I have a form to create a product and add to the database, the product should have many colors and each color should have many images.

How can I make this?

I tried

<input type="file" name="images[]" class="form-control-file col-md-5" required value=""> 

<input type="text" name="color[]" value="" class="form-control col-md-2">

foreach($request->file('images') as $index => $file){
    $img = time() . $file->hashName();
    $picpath=$file->storeAs(
        'upload/images', $img );

    $imgdevice = new Images();
    $imgdevice->url = $img;
    $imgdevice->color = request('color')[$index];
    $imgdevice->save();

    $device->images()->attach($imgdevice->id);
}

How can I create these arrays and then post them to the database?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ULx2Wx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire