Use of undefined constant DOMAIN – assumed ‘DOMAIN’ in Laravel

I am developing doc management system using laravel 7. I am trying to integrate the SMS api but i am facing this error. $url = trim(DOMAIN, ‘/’).”/api/v3/send-sms”;. I cant recognize. Any one can help me? I have also attach the image check it the bellow.

This is my SMS api script.

const API_TOKEN = "52b0e465-2202-438a-b50f"; 
    const SID = "KODERAASK"; 
    const DOMAIN = "https://sms.ssl.com"; 
    
    
    function singleSms($msisdn, $messageBody, $csmsId)
    {
        $params = [
            "api_token" => "52b0e465-2202-438a-b50f",
            "sid" => "KODMASK",
            "msisdn" => $msisdn,
            "sms" => $messageBody,
            "csms_id" => $csmsId
        ];

        $url = trim(DOMAIN, '/')."/api/v3/send-sms";
        $params = json_encode($params);
    
    callApi($url, $params);
    }
    
    
    function callApi($url, $params)
    {
        $ch = curl_init(); // Initialize cURL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($params),
            'accept:application/json'
        ));
    
        $response = curl_exec($ch);
    
        curl_close($ch);
    
        return $response;
    }
    

That is my custom method (singleSms($msisdn, $messageBody, $csmsId) ) I call this function with parameter in this method.

    public function requestcreat(Request $request) 
       {    
    
        $data = new Requestcash([ 
        'rappid' =>$request->get('apid'),
        'sendsms' =>$request->get('details'),
        ]);
        
      $data->save();
        
        $sendsms=$request->get('details'); 
        $number=$request->get('mobilenumber');
        $messageBody=$request->get('details');

        $msisdn=$request->get('mobilenumber');
        $csmsId = "4437343343P3Z";
        $this->singleSms($msisdn, $messageBody, $csmsId);
    
      return redirect()->back()->with('success', 'delivered the sms');
    
    }

Please check the image i gave screen shoot

Answer

php doesn’t know what DOMAIN is unless you specify it. In this case you initialized in the const so just call it.

$url = trim(self::DOMAIN, '/')."/api/v3/send-sms";

EDIT: based on @brombeer comment, you should put the API_TOKEN and SID into the .env file.