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

参数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 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题