<?php

namespace App\Http\Controllers;

use App\Models\ConfSmartupdate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class TestController extends Controller
{
    //

    public function  index() {

      
            $numServerSubquery = DB::table('conf_server_pendding as p2')
                ->select(DB::raw('count(p2.ServerID) as NUMSERVER'), 'p2.PatchID')
                ->groupBy('p2.PatchID');

            // Query หลัก
            $query = ConfSmartupdate::from('conf_smartupdate as p1')
                ->select('p1.PID', 'p1.PATCHNAME', 'p1.PDESC', 'p1.PDATE', 'p1.PLEVEL', 'p1.Remark', 'p3.NUMSERVER')
                ->leftJoinSub($numServerSubquery, 'p3', function ($join) {
                    $join->on('p1.PID', '=', 'p3.PatchID');
                });

            // if ($this->searchSelected && $this->keyword) {
            //     $query->where($this->searchSelected, 'LIKE', '%' . $this->keyword . '%');
            // }
            $query->orderBy('p1.PID', 'DESC');
            $results = $query->paginate(10);
      
        return view('test' , compact('results'));
    }
}
 