You should never use env() outside of config files. It will return null as soon as you cache config
Mar 8, 2022
7
Level 27
stdClass::$results
Hello,
I get this error message:
Undefined property: stdClass::$results
RajaOngkir.php
public static function get_province()
{
//
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.rajaongkir.com/starter/province",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"key: ". env('RAJAONGKIR_KEY')
//
),
));
Suprising enough the result of dd(env('RAJAONGKIR_KEY')) is null
I already define RAJAONGKIR_KEY, I wonder why it is still null ?
ref: https://stackoverflow.com/questions/25417312/laravel-model-returns-undefined-property-stdclassname
Please or to participate in this conversation.