0
<?php 

$apiMonitor = DB::table('sites')->select('uptime_access_code')->get();

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.uptimerobot.com/v2/getMonitors",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "api_key=Private&format=json&logs=1&monitors=$apiMonitor&custom_uptime_ratios=1-7-30",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
 ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

  if ($err) {
   echo "cURL Error #:" . $err;
} else {
$data = json_decode($response);
$custom_uptime = ($data->monitors[0]->custom_uptime_ratio);
$uptime = explode("-",$custom_uptime);
}

?>

I already get my value of my uptime access but its an array The thing is my monitor need only the value but when i dd() it this what happens.

This is my dd($apiMonitor);

apiMonitor

The output I want to happen is

CURLOPT_POSTFIELDS => "api_key=Private&format=json&logs=1&monitors=778780885&custom_uptime_ratios=1-7-30",

The output that you can see is working already but how can I able to get the data from the database and put the value of uptime_access_code to my monitor? Thank you.

1 Answer 1

2

get() returns a collection of all of the rows, since you're getting just one column and not specifying a where clause. If you only want one value, you can use value to get a single value (previous versions used pluck)

$apiMonitor = DB::table('sites')->value('uptime_access_code');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.