<?php

namespace App\Http\Controllers\Radius;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class Get_Srvid extends Controller
{
    public function getsrvid(Request $request)
    {
    
        $link = mysqli_connect("172.27.0.5", "anwar", "4nsw3r", "radius");

        /* check connection */
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
        }

        // $car = (isset($_GET['car']) ? $_GET['car'] : null);

        $query = "SELECT `srvid`,`srvname`,`custattr`,`descr`,`enableservice` FROM `rm_services`";

        if ($result = mysqli_query($link, $query)) {

            $newArr = array();
            /* fetch associative array */
            while ($db_field = mysqli_fetch_assoc($result)) {
                $newArr[] = $db_field;
            }
            return response()->json(['status' => 200,'message' => $newArr], 200);; // get all products in json format.    
        }

    }
    public function getbysrvid($id)
    {
    
        $link = mysqli_connect("172.27.0.5", "anwar", "4nsw3r", "radius");

        /* check connection */
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
        }

        // $car = (isset($_GET['car']) ? $_GET['car'] : null);

        $query = "SELECT `srvid`,`srvname`,`custattr`,`descr`,`enableservice` FROM `rm_services` where `srvid` = $id ";

        if ($result = mysqli_query($link, $query)) {

            $newArr = array();
            /* fetch associative array */
            while ($db_field = mysqli_fetch_assoc($result)) {
                $newArr[] = $db_field;
            }
            return response()->json(['status' => 200,'message' => $newArr], 200);; // get all products in json format.    
        }

    }
}
