dsvtnz6350 2018-10-23 22:34
浏览 550
已采纳

参数2传递给Symfony \ Component \ HttpFoundation \ Cookie :: __ construct()必须是string或null类型,给出数组

I have updated my laravel version from 5.5 to 5.6 and followed the update guide but there is one error that I cannot figure out.

Error

Argument 2 passed to Symfony\Component\HttpFoundation\Cookie::__construct() must be of the type string or null, array given

My code generating this error:

public function show($id, DealService $dealService, CookieJar $cookieJar)
    {
        if(null != $coupon = $dealService->getActiveDealById($id))
        {
            if(!Cookie::has('recent'))
            {
                $ids = [];
                array_unshift($ids, $id);
                $cookieJar->queue('recent', $ids);
            }
            else
            {
                $ids = Cookie::get('recent');
                if(!in_array($id, $ids))
                {
                    array_unshift($ids, $id);
                    $ids[] = $id;
                    $cookieJar->queue('recent', $ids);
                }
            }
            if(!empty($ids))
            {
                $recent_deals = $dealService->getDealsByIds($ids);
            }
            $related_deals = $dealService->getRelatedActiveDeals($id);

            return view('couponia.show', ['coupon' => $coupon, 'recent_deals' => $recent_deals, 'related_deals' => $related_deals]);
        }
        else
        {
            return view('errors.404');
        }
    }

CookieJar queue method throws the exception as it is trying to create a Cookie instance, but this code used to work perfectly in 5.5 and the CookieJar documentation also suggests that it accepts array as argument.

  • 写回答

1条回答 默认 最新

  • duanfuxing2212 2018-10-27 10:31
    关注

    The Problem was that after the update the Symphony Library was also updated to version 3.3 which does not support array cookies anymore. At this point a solution could be to serialize the array and then unserialize.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失