【问题标题】:Laravel Queue not able to convert class object to stringLaravel 队列无法将类对象转换为字符串
【发布时间】:2019-09-18 09:11:13
【问题描述】:

问题是当我将长编码字符串作为参数传递来创建一个类的对象时,我得到了错误,下面是我的代码:-

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

ReProcessShipment 类句柄函数

$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);
        }

在日志中我得到错误:

App\Jobs\ReProcessShipment 类的对象无法转换为 string {"exception":"[object] (ErrorException(code: 0): Object of 类 App\Jobs\ReProcessShipment 无法在

处转换为字符串

【问题讨论】:

    标签: laravel-5 queue


    【解决方案1】:

    您是否尝试过为 ReProcessShipment 对象实现 __toString() 函数?

    字符串转换似乎是错误的原因,__toString 应该允许通过返回您选择的对象的字符串版本来进行正确的转换。

    【讨论】:

    • able 只是实现的一个例子,但是 laravel 内部调用它,同时将类对象保存在 table 中
    • 很抱歉我没听懂。错误不是由“return (string)$job;”产生的吗? ?
    • No laravel queue ReProcessShipment::dispatch($job); 这会产生错误
    猜你喜欢
    • 1970-01-01
    • 2019-12-28
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多