Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

adding multiple vaules at once in sql laravel

$
0
0

I have created a form to insert data to sql.

I am trying to add multiple values to sql database by adding more rows with java script but i am getting only the data entered to database from first row only.

If you could take minute of your day to take a look, i would really appreciate it

@php($uid = rand(11,999))
<div class="row" id="mobileDiv{{ $uid }}">

<div class="input-field col s3">
<i class="mdi-editor-mode-edit prefix"></i>
{!! Form::text('rcountry[]',null,['id' => 'rcountry'.$uid]) !!}
<label for="rcountry{{ $uid }}" class="active">Country</label>
</div>

<div class="input-field col s3">
<i class="mdi-editor-mode-edit prefix"></i>
{!! Form::text('ryear[]',null,['id' => 'ryear_'.$uid]) !!}
<label for="ryear_{{ $uid }}" class="active">Year</label>
</div>

<div class="input-field col s3">
<i class="mdi-editor-mode-edit prefix"></i>
{!! Form::text('reason[]',null,['id' => 'reason_'.$uid]) !!}
<label for="reason_{{ $uid }}" class="active">Reason</label>
</div>

<div class="input-field col s2">
<a href="javascript::void()" style="color:red" onclick="Remove(mobileDiv{{ $uid }})"><i class="fa fa-trash fa-2x"></i></a>
</div>
</div>

<div style="margin-left:20px">
<button type="button" class="btn blue" onClick="AddRefusal();"><i class="fa fa-plus"></i></button>
</div>

<script>
function AddRefusal() {


    $("<DIV>").load("{{ Asset('addRefusal') }}", function() {

            $("#refusal").append($(this).html());
    }); 
}
</script>

controller file is like

public function addRefusal($data,$id)
    {       
        $rcountry  = isset($data['rcountry']) ? $data['rcountry'] : [];
        $ryear = isset($data['ryear']) ? $data['ryear'] : [];
        $reason = isset($data['reason']) ? $data['reason'] : [];

        for($i=0;$i<count($rcountry);$i++)
        {
            $add                = new Refusal;
            $add->branch_id     = IMS::bid();
            $add->enquiry_id    = $id;
            $add->rcountry      = $rcountry[$i];
            $add->ryear         = $ryear[$i];
            $add->reason        = $reason[$i];
            $add->save();
        }
    }

Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>