The issue sounds more like that $categories
is already a Collection
, not a Builder
. Both the Collection
and the Builder
have a where()
method, but their logic is not the same.
The where()
method on the Builder
will add a parameterized where clause to the query run against the database. In this case, the type of variable doesn't matter.
However, the where()
method on the Collection
will loop through the collection and return those results where the field in the first parameter is strictly equal (===
) to the value passed in the second parameter. To change this, you can pass false
as the third parameter, and it will use a loose comparison (==
) instead of strict. Additionally, you could use whereLoose()
, which is a shortcut for where()
with the third parameter as false
.
$array[] = $categories->where('pk_i_id', $category_id, false)->first();
// or
$array[] = $categories->whereLoose('pk_i_id', $category_id)->first();
If the incorrect field types are causing more issues that what you've described, then you may want to work on fixing the underlying issue. As has been pointed out in the linked posts, on your LAMP stack you need to replace the mysqld
driver with the mysqlnd
driver.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…