1. Go to this page and download the library: Download romdh4ne/laravel-querycraft library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// ❌ N+1 — fires one query per user
$users = User::all();
foreach ($users as $user) {
echo $user->company->name;
}
// ✅ Fix — one query total
$users = User::with('company')->get();
User::where('email', $email)->first(); // no index on email
// Fix — in a migration:
$table->index('email');
$table->index(['status', 'created_at']); // composite
// ❌ Duplicate — same query + same values fired twice
$settings = Setting::all();
// ... somewhere else in the same request ...
$settings = Setting::all();
// ✅ Fix
$settings = Cache::remember('settings', 3600, fn() => Setting::all());