1. Go to this page and download the library: Download mojahed/multiquery 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/ */
mojahed / multiquery example snippets
use Mojahed\Facades\MultiQuery;
[$users, $orders, $revenue] = MultiQuery::run([
"SELECT COUNT(*) as total FROM users",
"SELECT COUNT(*) as total FROM orders",
"SELECT SUM(amount) as total FROM payments",
]);
// ❌ Wrong — mq('count') with groupBy only returns first row
Order::groupBy('status')->mq('count')
// ✅ Correct — write the aggregate, use mq('get')
Order::selectRaw('status, COUNT(*) as total')
->groupBy('status')
->mq('get')
// ❌ Won't load relations — with() is ignored
User::with('orders')->mq('get')
// ✅ Use join instead
User::select('users.*', 'orders.amount')
->join('orders', 'orders.user_id', '=', 'users.id')
->mq('get')
// ✅ Or run relations as separate parallel queries
MultiQuery::run([
'users' => User::mq('get'),
'orders' => Order::whereIn('user_id', [1, 2, 3])->mq('get'),
]);