$draw_date = $request->input('date');
$category_id = $request->input('cat_id');
$limit = $request->input('limit') ? $request->input('limit') : 100;
if($category_id != '' || $category_id != null) {
$query = ['lotto_results.category_id' => $category_id, 'lotto_results.draw_date' => $draw_date];
} else {
$query = ['lotto_results.draw_date' => $draw_date];
}
$results = LottoResult::select('lotto_results.id', 'lotto_results.category_id', 'lotto_results.num_1', 'lotto_results.num_2', 'lotto_results.num_3', 'lotto_results.num_4', 'lotto_results.num_5', 'lotto_results.num_6', 'lotto_results.draw_date', 'lotto_results.jackpot', 'lotto_results.winners', 'lotto_categories.name', 'lotto_categories.logo', 'lotto_categories.is_major')
->join('lotto_categories', 'lotto_categories.id', '=', 'lotto_results.category_id')
->where($query)
->orderBy('draw_date', 'DESC')
->paginate($limit);