I want to compare two values of the database. Is it possible to do so with the "where" method? For example, the "tnx_time" would be one DB value and the "value(duration)" the other one. But I cannot now access the DB values on the 3rd field of the "where" function.
Does anybody know how to fix that?
$trnxs = Transaction::where('tnx_time', '<', date("Y-m-d", strtotime( value(duration) )) )
CodePudding user response:
Try storing the value first so you can properly compare it.
$duration = value(duration);
$date = date("Y-m-d", strtotime($duration));
$trnxs = Transaction::where('tnx_time', '<', $date);
CodePudding user response:
You can use a callback in your "where" clause to create a subquery, would be something like this (might need some changing)
$trnxs = Transaction::where('tnx_time', '<', function ($query) {
$query->selectRaw('date("Y-m-d", strtotime(value(duration)))');
})->get();