<?php
require 'vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

$search = 'a';
$query = App\Models\Peminjaman::where(function($q) use ($search) {
    $q->whereHas('user', function($qUser) use ($search) {
        $qUser->where('name', 'like', "%{$search}%");
    })->orWhereHas('buku', function($qBuku) use ($search) {
        $qBuku->where('judul', 'like', "%{$search}%");
    });
});

echo "SQL:\n";
echo $query->toSql() . "\n";
echo "Bindings:\n";
print_r($query->getBindings());
echo "Count:\n";
echo $query->count() . "\n";
