如何使 dd() 正常工作?

问题描述 投票:0回答:1

我正在尝试在 Laravel 应用程序中使用 dd() 进行调试,但是在我的 http 请求的网络预览中,我得到了这个脚本,而不是应该位于 $all_ids 数组中的数据预览

%3Cscript%3E%20Sfdump%20%3D%20window.Sfdump%20%7C%7C%20(function%20(doc)%20%7B%20doc.documentElement.classList.add('sf-js-enabled')%3B%20var%20rxEsc%20%3D%20%2F(%5B.*%2B%3F%5E%24%7B%7D()%7C%5C%5B%5C%5D%5C%2F%5C%5C%5D)%2Fg%2C%20idRx%20%3D%20%2F%5Cbsf-dump-%5Cd%2B-ref%5B012%5D%5Cw%2B%5Cb%2F%2C%20keyHint%20%3D%200%20%3C%3D%20navigator.platform.toUpperCase().indexOf('MAC')%20%3F%20'Cmd'%20%3A%20'Ctrl'%2C%20addEventListener%20%3D%20function%20(e%2C%20n%2C%20cb)%20%7B%20e.addEventListener(n%2C%20cb%2C%20false)%3B%20%7D%3B%20if%20(!doc.addEventListener)%20%7B%20addEventListener%20%3D%20function%20(element%2C%20eventName%2C%20callback)%20%7B%20element.attachEvent('on'%20%2B%20eventName%2C%20function%20(e)%20%7B%20e.preventDefault%20%3D%20function%20()%20%7Be.returnValue%20%3D%20false%3B%7D%3B%20e.target%20%3D%20e.srcElement%3B%20callback(e)%3B%20%7D)%3B%20%7D%3B%20%7D%20function%20toggle(a%2C%20recursive)%20%7B%20var%20s%20%3D%20a.nextSibling%20%7C%7C%20%7B%7D%2C%20oldClass%20%3D%20s.className%2C%20arrow%2C%20newClass%3B%20if%20(%2F%5Cbsf-dump-...

它在 30 分钟前工作,我确实尝试清除缓存,但没有帮助。这是我使用 dd() 的代码

  public function viewAllProductInfo(Request $request)
    {
        $all_ids = $request->id;
        foreach ($all_ids as $id) {
            dd($all_ids);
            $storeItemProduct = StoreItemProduct::findOrFail($id);
            event(new StoreViewItemProductLabelEvent($storeItemProduct, $request->all()));
        }
    }

我希望这篇文章能找到有这方面经验的人。

php laravel google-chrome debugging
1个回答
0
投票

您可以在代码中的战略位置使用 dd() ,如下所示, 并不是说在 foreach 循环中你转储特定的 id,而不是数组

public function viewAllProductInfo(Request $request)
{
    $all_ids = $request->id;
    dd($all_ids); // Dump the $all_ids array before entering the loop
    foreach ($all_ids as $id) {
        dd($id); // Dump each $id before fetching the corresponding StoreItemProduct
        $storeItemProduct = StoreItemProduct::findOrFail($id);
        event(new StoreViewItemProductLabelEvent($storeItemProduct, $request->all()));
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.