Repository: laravel/framework (php)

Issue:
findMany breaking change
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: v9.46.0
- PHP Version: 8.1
- Database Driver & Version: MySql 5.7

### Description:
https://github.com/laravel/framework/pull/45453 On this pr and in the release of 9.46 the behaviour of findMany changed.
Consider the following query Category::query()->findMany($categoryIds) where the categoryIds has the following format:
array:2 [ 
  0 => array:1 [
    "category_id" => 34234234
  ],
 1 => array:1 [
    "category_id" => 6756767567
  ]
];

And because it would use the regular whereIn method it would basically flatten the array resulting in the query 
"where id IN (34234234,6756767567)".

After that change we are using the IntegerInRaw which casts the array to int resulting in the query of where id IN (1,1).


Don't know if that was intentional or not but it does change the previous behaviour.

### Steps To Reproduce:
Basically pass an array of arrays in the findMany in latest version of the framework


Pull request description:
[9.x] Fixes 45582 issue 🔧
This fixes #45582 
Since the `Builder\Query` flattens the binding array before applying it a method like `whereIn` can accept an associative array as its second argument (as demonstrated in the added tests).
So to make `whereIntegerInRaw` compatible with `whereIn` we need to flatten the values before casting it to int.
@staudenmeir 

- Missing tests are added.

![image](https://user-images.githubusercontent.com/6961695/211535390-73f6782f-f17f-4f7d-9560-c0ee24a52b76.png)

- The `whereIn` method tries to avoid accepting nested arrays as `$values` with the check below, but it is not enough and can be bypassed with an input like this:
```
 ->whereIn('id', [
     ['id' => 1 ], 
     ['id' => 2 ]
 ]) 
``` 

and due to the above flattening, it will continue to work as if it was called like this:
```
->whereIn('id', [1, 2])
 ```

![image](https://user-images.githubusercontent.com/6961695/211540349-a96ca81e-962a-43d6-8d4a-1fb77e3225ce.png)



Patch:
diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php
index b1bde865d8..b06a43fe00 100755
--- a/src/Illuminate/Database/Query/Builder.php
+++ b/src/Illuminate/Database/Query/Builder.php
@@ -1094,6 +1094,8 @@ public function whereIntegerInRaw($column, $values, $boolean = 'and', $not = fal
             $values = $values->toArray();
         }
 
+        $values = Arr::flatten($values);
+
         foreach ($values as &$value) {
             $value = (int) $value;
         }


Test patch:
diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php
index 2d0359ee1f..6c93a076f5 100755
--- a/tests/Database/DatabaseQueryBuilderTest.php
+++ b/tests/Database/DatabaseQueryBuilderTest.php
@@ -936,12 +936,46 @@ public function testBasicWhereIns()
         $this->assertSame('select * from "users" where "id" in (?, ?, ?)', $builder->toSql());
         $this->assertEquals([0 => 1, 1 => 2, 2 => 3], $builder->getBindings());
 
+        // associative arrays as values:
+        $builder = $this->getBuilder();
+        $builder->select('*')->from('users')->whereIn('id', [
+            'issue' => 45582,
+            'id' => 2,
+            3,
+        ]);
+        $this->assertSame('select * from "users" where "id" in (?, ?, ?)', $builder->toSql());
+        $this->assertEquals([0 => 45582, 1 => 2, 2 => 3], $builder->getBindings());
+
+        // can accept some nested arrays as values.
+        $builder = $this->getBuilder();
+        $builder->select('*')->from('users')->whereIn('id', [
+            ['issue' => 45582],
+            ['id' => 2],
+            [3],
+        ]);
+        $this->assertSame('select * from "users" where "id" in (?, ?, ?)', $builder->toSql());
+        $this->assertEquals([0 => 45582, 1 => 2, 2 => 3], $builder->getBindings());
+
         $builder = $this->getBuilder();
         $builder->select('*')->from('users')->where('id', '=', 1)->orWhereIn('id', [1, 2, 3]);
         $this->assertSame('select * from "users" where "id" = ? or "id" in (?, ?, ?)', $builder->toSql());
         $this->assertEquals([0 => 1, 1 => 1, 2 => 2, 3 => 3], $builder->getBindings());
     }
 
+    public function testBasicWhereInsException()
+    {
+        $this->expectException(InvalidArgumentException::class);
+        $builder = $this->getBuilder();
+        $builder->select('*')->from('users')->whereIn('id', [
+            [
+                'a' => 1,
+                'b' => 1,
+            ],
+            ['c' => 2],
+            [3],
+        ]);
+    }
+
     public function testBasicWhereNotIns()
     {
         $builder = $this->getBuilder();
@@ -999,6 +1033,15 @@ public function testWhereIntegerInRaw()
         $builder->select('*')->from('users')->whereIntegerInRaw('id', ['1a', 2]);
         $this->assertSame('select * from "users" where "id" in (1, 2)', $builder->toSql());
         $this->assertEquals([], $builder->getBindings());
+
+        $builder = $this->getBuilder();
+        $builder->select('*')->from('users')->whereIntegerInRaw('id', [
+            ['id' => '1a'],
+            ['id' => 2],
+            ['any' => '3'],
+        ]);
+        $this->assertSame('select * from "users" where "id" in (1, 2, 3)', $builder->toSql());
+        $this->assertEquals([], $builder->getBindings());
     }
 
     public function testOrWhereIntegerInRaw()