I have below table consols:
Schema::create('consols', function (Blueprint $table) {
$table->bigIncrements('id');
$table->double('current_weight', 8, 3)->default(0);
$table->double('current_weight', 8, 3)->default(0);
$table->double('final_weight', 8, 3)->default(0);
$table->double('final_cbm', 8, 3)->default(0);
$table->timestamp('finals_sent', 0)->nullable();
});
Which contain an entry like below:
id | current_weight | current_cbm | final_weight | final_cbm | finals_sent |
-----------------------------------------------------------------------------------|
1 | 45.000 | 1.000 | 200.000 | 10.000 | 2019-09-26 10:03:59 |
I have written a scope on my model Consol, to filter the entries, where: finals_sent is not null, current_weight > final_weight OR current_cbm > final_cbm:
public function scopeOfCurrentGreaterThanFinals($query)
{
return $query->whereNotNull('finals_sent')->where(function ($query) {
$query->where('current_weight', '>', 'final_weight')
->orWhere('current_cbm', '>', 'final_cbm');
});
}
When I use it and dump it out - I am expecting to see no results:
$consols = Consol::ofCurrentGreaterThanFinals()
->orderBy('awb', 'DESC')
->get()
->toArray();
However, the entry above is still being shown:
array:1 [▼
0 => array:24 [▼
"id" => 1
"current_weight" => 45.0
"current_cbm" => 1.0
"final_weight" => 200.0
"final_cbm" => 10.0
"finals_sent" => "2019-09-26 10:03:59"
]
]
I am not sure what I am doing wrong? I think I cleary states that I only want to see the results, where:
- current_weight > final_weight or
- current_cbm > current_weight and
- finals_sent is not null
And above entry does not fit this, because the current_weight and current_cbm is clearly not higher than the final_weight and final_cbm.
What am I doing wrong?