jeudi 9 février 2017

Laravel save multiple record at once

have a problem to save multiple records at once. This is my form

    {!! Form::open(array('url'=>'pipeline/save?return='.$return, 'class'=>'form-horizontal','files' => true , 'parsley-validate'=>'','novalidate'=>' ')) !!}
    @foreach($destinazioni as $destinazione)
    <div class="col-md-2 col-md-offset-2 text-left">
        <input type="text" name="destination[]" readonly class="form-control" value=""/>

    </div>

    <div class="col-md-6 text-left">
        <select name="target[]" class="form-control">
        <option value="Nessuna">Seleziona...</option>
        @foreach($campi->keys() as $target)
        <option value="">  </option>
        @endforeach
        </select>
    </div>
    @endforeach
        @if(!empty($profilo->set_attributi))
            @foreach($profilo->attributi as $attributo)
            <div class="col-md-2 col-md-offset-2 text-left">
                <input type="text" name="destination[]" readonly class="form-control" value=""/>
            </div>
            <div class="col-md-6 text-left">
        <select name="target[]" class="form-control">
        <option value="Nessuna">Seleziona...</option>
        @foreach($campi->keys() as $target)
        <option value="">  </option>
        @endforeach
        </select>
    </div>
    @endforeach
@endif
<div style="clear:both"></div>  


                  <div class="form-group" style="margin-top:5%">
                    <label class="col-sm-4 text-right">&nbsp;</label>
                    <div class="col-sm-8">  
                    <button type="submit" name="apply" class="btn btn-info btn-sm" ><i class="icon-checkmark-circle2"></i> </button>
                    <button type="submit" name="submit" class="btn btn-primary btn-sm" ><i class="icon-bubble-check"></i> </button>
                    <button type="button" onclick="location.href='' " class="btn btn-warning btn-sm "><i class="icon-cancel-circle2 "></i>   </button>
                    </div>    

                  </div>

         {!! Form::close() !!}

This is controller where i try to handle inserting of data:

$rules = $this->validateForm();
    $validator = Validator::make($request->all(), $rules);  
    if ($validator->passes()) {
        $request = array('destination' => $request->input('destination'), 'target' => $request->input('target'));
        foreach ($request as $req) {
            $destination = new Pipeline;        
            $destination->destination = $req->destination;
            $destination->target = $req->target;
            $destination->save();
        }

        return Redirect::to('pipeline')->with('messagetext',\Lang::get('core.note_success'))->with('msgstatus','success');

But actually i get Try to get proprety of non object error. I have also tried with Pipeline::insert($data) method but it return wrong names of column error



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire