lundi 22 février 2016

Find rows matching values from array

I have a form where user select one or more checkboxes like this:

{!! Form::Label('faults', 'Please select one of the following that best describes your device') !!}
                                            <div class="form-group">                                            
                                                @foreach($faults as $fault)
                                                <div class="col-md-4">
                                                    <span><i class="fa fa-question-circle" rel="popover" data-content="{{$fault->fault_tooltip}}"></i></span>
                                                    <label class="checkbox-inline">
                                                    <input id="faults" type="checkbox" name="faults[]" value="{{$fault->id}}">{{$fault->fault}}
                                                    </label>
                                                </div>
                                                @endforeach
                                            </div>

Now in my controller I am getting the input for faults like this:

$faults = Input::get('faults');

This returns something an array contining the ID's for each fault like this:

    array:2 [▼
  0 => "37"
  1 => "36"
]

I need to loop through the array and find each row in my faults table matching each id from the array and get other values like $fault->name and $fault->price.

I know this is pretty easy but I am starting with coding and I can't get my head around.

Any help will be much appreciated.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire