I'm stuck in a filter:
These are my tables:
My model for Movement
public function factura() {
return $this->belongsTo('App\Factura');
}
public function cuenta() {
return $this->belongsTo('App\Cuenta');
}
public function centroCosto() {
return $this->belongsTo('App\CentroCosto');
}
public function scopeFfecha($query, $fdesde=NULL, $fhasta=NULL)
{
if ($fdesde)
$query=$query->where('fechaContable','>=',$fdesde);
if ($fhasta)
$query=$query->where('fechaContable','<=',$fhasta);
return $query;
}
and for my controller:
public function show(Request $request, $id)
{
$fdesde= $request->get('fdesde');
$fhasta=$request->get('fhasta');
$movimientos=Movimiento::wherecuenta_id($id)->with('factura')
->ffecha($fdesde,$fhasta)
->get();
return view('resultado.show',compact('movimientos'));
}
The problem is that since the field fechaContable
is not in the table, the filter fails and returns the entire data collection.
I have already checked the date parameters returned by $ request and they are correct.
I need to show all the records of movimientos
that meet the condition of cuenta_id
and the rank of fechaContable
, so if I reverse the relationship (filter the invoice date first) anyway I will have the same problem because I will have to filter by the field cuenta_id
of the table movements.