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.

2022-11-18 (deployed)

collect($request->ids)
  ->filter(fn ($id) => $id)
  ->map(fn (int $id) => Post::find($id)?->id)
  ->reject(fn ($post) => !$post)
  ->toArray();
// 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 () {
	// ...
});
<?php

function my_str_helper()
{
		// ...
}

2022-11-19 (deployed)