I have been looking for a solution to this problem for some time but I have not found anything that I can adapt.
There are two tables ordensiembras
and siembras
, one order can have several sowings.
The Ordensiembras model:
public function sembrado() {
return $this->hasMany('App\Siembra');
}
I need to generate a scope with values 1 if it has not been executed ( cantReal==0
) 2 if it is completed (the sum of cantReal==cantOrden
) and 3 if it is incomplete ( cantReal<cantOrden
)
public function scopeCompletado($query, $fcompletado)
{
if($fcompletado==1)
return $query->where('???????');
if($fcompletado==2)
return $query->where('???????');
if($fcompletado==3)
return $query->where('???????');
}
I could review the amount of siembras.canReal
in the view and not show the records that do not meet the criteria, but in this case the paging does not work.