1
I have the following tables, Condominios
and CondominiosTaxas
, that are a relationship 1:N
, respectively, my relationship in the model Condominio:
public function Taxas()
{
return $this->hasMany('WebCondom\Models\Condominios\CondominioTaxa',
'CondominioCOD',
'CondominioID');
}
My relationship in the model Condominiotaxa:
public function Condominio()
{
$this->belongsTo('WebCondom\Models\Condominios\Condominio',
'CondominioCOD',
'CondominioID');
}
What happens is this, I need to register the condo fee on a form, and when registering the condo, choose the N rates I want.
However, when making the association, I do not know what to do, because the method sync()
exists only in a relationship N:N
, I tried to create the condominium, and in it call my relationship and the method sync()
passing the rate array, but the error is generated:
Call to Undefined method Illuminate Database Query Builder::Sync()
I wanted to know how can I do this without having to create an N:N relationship, remembering that in this case, although they are fees, a condominium fee has to be independent of another condominium, because if a condominium changes its (own) rate, it cannot affect other condominiums.
Field rates on 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>
Fees arrive as follows in the controller:
array:3 [▼
0 => "1"
1 => "2"
2 => "3"
]
You should then register a fee for each condominium and this if you have to do via coding, is a rule of its own independent of how the
Laravel
will save relation data.– novic