How would you go about inserting a php variable $date into an eloquent whereRaw? The following will work with curDate() but can't pass a variable through.
$ex = User::whereRaw('month({$date}) = month(dob) and day($date) = day(dob)')->get();
I don't know whether the value of date will decided by user or php script but you always have to prepare raw statement by PDO,
Your raw statement will look like (safe)
$ex = User::whereRaw('month(?) = month(dob) and day(?) = day(dob)')->setBindings([$date, $date])->get();
Or
$ex = User::whereRaw("month($date) = month(dob) and day($date) = day(dob)")->get();
Also you have to look into this answer, PHP - concatenate or directly insert variables in string
You may try by replacing '
with "
$ex = User::whereRaw("month({$date}) = month(dob) and day($date) = day(dob)")->get();