phplaravel-5queue

Laravel Queue not able to convert class object to string


The Issue is when I pass long encoded string as parameter to create object of a class I get error here is my code below:-

 $job=new ReProcessShipment("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPFJlcXVlc3Q+
        CiAgPFRyYW5zSWQ+NjU3MTA8L1RyYW5zSWQ+CiAgPEFjY291bnRJZD5NWUdPPC9B
        Y2NvdW50................."); //8477 charter long encoded string
         ReProcessShipment::dispatch($job);

ReProcessShipment Class handle function

$request_data['request_data'] =  $this->data_get;
        $request_data['service'] ='shipment_order_relay';
        $webservice_data = Webservice::create($request_data);

        try {
            $value = urldecode($this->data_get);
            $value = base64_decode($value);
            $value = str_replace("&", "&", $value);
            $result = $this->insert_stg_shipment($value, $webservice_data->id);
        } catch (Exception $e) {
            $value = base64_decode($this->data_get);
            $value = str_replace("&", "&", $value);
            $result = $this->insert_stg_shipment($value, $webservice_data->id);
        }

in Logs I get error:

Object of class App\Jobs\ReProcessShipment could not be converted to string {"exception":"[object] (ErrorException(code: 0): Object of class App\Jobs\ReProcessShipment could not be converted to string at


Solution

  • Have you tried implementing a __toString() function for the ReProcessShipment object ?

    The string cast seems to be the cause of the error and __toString should allow a correct conversion by returning the string version of your object that you have chosen.