I have something that I don't quite understand, I have the solution, but I don't know why and it's driving me a bit crazy
Controller
DB::connection()->enableQueryLog();
$transfer = Transfer::where('ticket_id', $last_ticket)->where('event_id', 36)->where('buyer', $user_email)->first();
$queries = DB::getQueryLog();
dd($queries);
Result
array:1 [
0 => array:3 [
"query" => "select * from `transfers` where `ticket_id` = ? and `event_id` = ? and `buyer` = ? limit 1"
"bindings" => array:3 [
0 => false
1 => 36
2 => "[email protected]"
]
"time" => 0.36
]
]
Situation:
$last_ticket in the DB is unique and never null, empty or false.
In my example $last_ticket is false, but in the DB there's no any false, why do I still get results?
Is it because whenever one where condition is false, it doesn't take that into the equation?
So the question is: How can I do to receive the correct results meaning: if $last_ticket is false then no results, and if it has some data, then return the row result restricted by $last_ticket
One option could be to put if($last_ticket == false){$last_ticket='randomInexistentString_ag4dh&2g32y4t'} so it's not null or zero but I don't think it's the prettier way to go