Im trying to insert multiple models into the database but with no luck... I have a form (blade) looks like this:
@extends('layouts.properties')
@section('content')
{{ Form::open(['route' => 'properties.store', 'class' => 'uk-form', 'id' => 'properties-form']) }}
@for ($i = 0; $i < Auth::user()->properties_count; $i++)
<fieldset class="uk-margin-large-top property-field-{{ $i + 1 }}">
{{ Form::select('boro[]', ['Pick Borough', 'Manhattan', 'Bronx', 'Brooklyn', 'Queens', 'Staten Island']) }}
{{ Form::text('house_num[]', Input::old('house_num'), ['class' => 'uk-form-width-small', 'placeholder' => 'House Num']) }}
{{ Form::text('street[]', Input::old('street'), ['placeholder' => 'Street']) }}
</fieldset>
@endfor
{{ Form::submit('Save Properties', ['class' => 'uk-button uk-button-primary']) }}
{{ Form::close() }}
@stop
In the controller, I have: (used array_filter to clear the unset values if the user only filled in 2 properties)
$boro = array_filter(Input::get('boro'));
$house_num = array_filter(Input::get('house_num'));
$street = array_filter(Input::get('street'));
Now I'm stuck... can't figure it out how to loop thru 3 arrays and save it to multiple models (rows).
Note: In my User model I did set hasMany Properties relationship.
My Property model looks like: id user_id boro housenum street
So if in the arrays i have 2 addresses, I need to rows.
Any ideas?