-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.php
62 lines (51 loc) · 1.9 KB
/
Debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace App\Console\Commands;
use App\Models\Order;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Debug extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'debug';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Debug the issue';
/**
* Execute the console command.
*/
public function handle()
{
$search = '%W20%';
// Get the total pages count without using union
$query = Order::where('number', 'like', $search)
->orWhereHas('user', static fn ($subquery) => $subquery->where(
'name',
'like',
$search
));
DB::enableQueryLog();
// Get the total pages using union
$queryWithUnion = Order::where('number', 'like', $search)->union(
Order::whereHas(
'user',
static fn ($subquery) => $subquery->where('name', 'like', $search)
)
);
// Confirm that both query has the same number of results
$this->line('Total orders without union: <comment>'.$query->paginate(5)->total().'</comment>');
$this->line('Total orders with union: <comment>'.$queryWithUnion->paginate(5)->total().'</comment>');
// Check for the total using getCountForPagination
$this->line('Count for pagination without union: <comment>'.$query->toBase()->getCountForPagination().'</comment>');
$this->line('Count for pagination with union: <comment>'.$queryWithUnion->toBase()->getCountForPagination().'</comment>');
// Show the query used to retrieve the total for a union query
$this->line('Query used for getCountForPagination with union:');
$this->comment(collect(DB::getQueryLog())->last()['query']);
}
}