<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Betting;
use Illuminate\Database\Eloquent\Builder;

class BettingController extends Controller
{
    public function index()
    {
        $bettings = Betting::with(['game', 'agent', 'details'])
            ->where(function ($query) {
                $query->where('id', 'LIKE', '%' . request()->query('search', '') . '%')
                    ->orWhereHas('agent', function (Builder $query) {
                        $query->whereAny(['name', 'id'], 'LIKE',   '%' . request()->query('search', '') . '%');
                    })->orWhereHas('game', function (Builder $query) {
                        $query->where('id', 'LIKE',   '%' . request()->query('search', '') . '%');
                    });
            })
            ->whereDate('created_at', 'LIKE', '%' . request()->query('datetime', '') . '%')
            ->latest('id')
            ->paginate(50);

        return view('admin.bettings.index', compact('bettings'));
    }
}
