There are some situations and edge-cases when N+1 query detection doesn’t work properly. The scope of this task is to explore and fix as many as possible.
!
in a closure:collect($request->ids)
->filter(fn ($id) => $id)
->map(fn (int $id) => Post::find($id)?->id)
->reject(fn ($post) => !$post)
->toArray();
return
statement before a DB transaction:// Worked well
public function execute()
{
DB::transaction(function () {
// ...
});
}
// Caused an error:
public function execute()
{
return DB::transaction(function () {
// ...
});
}
// Worked well
public function execute()
{
DB::transaction(function () {
// ...
});
}
// Caused an error:
public function execute()
{
$myService = app(MyService::class);
DB::transaction(function () {
// ...
});
}
// Woked well
Post::all()->map(function (Post $post) {
// ...
});
// Caused an error
$this->withExceptionHandling(function () {
// ...
});
namespace
it caused an error:<?php
function my_str_helper()
{
// ...
}