Created
April 3, 2023 21:27
-
-
Save sineld/6bf6264d7ca4d39e3f6e9339c3507414 to your computer and use it in GitHub Desktop.
Laravel Query Builder Bindings Date Where In Php Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dates = ['2023-03', '2023-04', '2023-05']; | |
$binds = implode(',', array_fill(0, count($dates), '?')); | |
$users = Illuminate\Support\Facades\DB::select( | |
"SELECT * FROM users WHERE DATE_FORMAT(created_date, '%Y-%m') IN ({$binds})", | |
$dates | |
); | |
dd($users); | |
array:3 [▼ | |
0 => {#1331 ▶} | |
1 => {#1339 ▶} | |
2 => {#1340 ▶} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment