<?php

namespace App\Http\Controllers\Parking;
use App\Parking_db\Lps;
use App\Path;
use App\Car;
use Illuminate\Http\Request;
use GuzzleHttp\Client;
use App\Http\Controllers\Controller;


class CameraController extends Controller
{
    public function index(){
        return view('camera',['title'=>'camera','body'=>'camera']);
    }

    public function callapi(){
        $query = Path::all();
        $main=Car::all();
        $client=new \GuzzleHttp\Client();
        $res = $client->request('GET', 'http://192.168.5.17:8086/query?q=select+last(plate)%2C*+from+%22in%22&db=NCUT_MM&pretty=true',['verify' => false]);
        $response = json_decode($res->getBody()->getContents(), true);
        $dbname=$response['results'][0]['series'][0]['name'];
        $columns=$response['results'][0]['series'][0]['columns'][3];
        $values=$response['results'][0]['series'][0]['values'][0][3];
        $car = Lps::All()->Where('status','已進場');

//        return $values[0];
        return View('index',['page' => 'smart_parking.camera','result'=>$query,'iresult'=>$main,'navbar_li'=>'smart_parking.layout.navbar_li','title'=>'camera','body'=>'camera','columns'=>$columns,"values"=>$values,'Cars'=>100-count($car)]);
    }
}
