Inserting data on side 1 of the ratio 1: N - Laravel 5

1

I have the following tables, Condominios and CondominiosTaxas , which are a 1:N relationship, respectively, my relationship in the Condominium model:

public function Taxas()
{
    return $this->hasMany('WebCondom\Models\Condominios\CondominioTaxa',
                          'CondominioCOD', 
                          'CondominioID');
}

My relationship in the CondominioTaxa model:

public function Condominio()
{
    $this->belongsTo('WebCondom\Models\Condominios\Condominio',
                     'CondominioCOD', 
                     'CondominioID');
}

What happens, is the following, I need to register the condominium fee on a form, and when to register the condominium, choose the N rates I want.

However, at the time of joining, I do not know what to do, because the sync() method only exists in a N:N relation, I tried to create the condominium, and call it my relationship and the sync() passing the rate array, but the error is generated:

  

Call to undefined method Illuminate \ Database \ Query \ Builder :: sync ()

I wanted to know how I can do this without having to create a N: N relationship, remembering that in this case, although they are fees, a fee for a condominium has to be independent of another condominium because if a condominium changes a rate (own), can not affect other condominiums.

Field rates in the form:

<div class="col-md-6">
   <div class="form-group">
     <label for="Taxas" class="control-label">Taxa</label>
     <select name="Taxas[]" id="Taxas" class="form-control" multiple="multiple">
       <option value="" selected disabled>---Nome taxa - valor taxa---</option>
       @foreach($taxas as $taxa)
          <option value="{{ $taxa->CondominioTaxaID }}">{{ $taxa->Taxa }}</option>
       @endforeach
     </select>
   </div>
</div>

The fees arrive as follows in the controller:

array:3 [▼
    0 => "1"
    1 => "2"
    2 => "3"
]
    
asked by anonymous 06.11.2017 / 11:57

0 answers