英文:
Laravel fullUrlWithoutQuery($keys) removes all parameters
问题
我有一个类似于 browse/gpus?architecture[0]=Type1&architecture[1]=Type2
的路由,我尝试在单击 a
标签时仅删除一个参数,所以我正在使用 fullUrlWithoutQuery('architecture')
,但它完全删除了两个参数,而不是只删除一个。
我尝试过 fullUrlWithoutQuery('architecture[]')
和 fullUrlWithQuery(['architecture[]' => null]
,但它们都会做同样的事情。有没有办法只删除可能的参数中的一个?
英文:
I have a route like browse/gpus?architecture[0]=Type1&architecture[1]=Type2
and I'm trying to make remove only one of the parameters when you click on an a
tag so I'm using fullUrlWithoutQuery('architecture')
however it completely removes both parameters instead of just one.
I've tried fullUrlWithoutQuery('architecture[]')
and fullUrlWithQuery(['architecture[]' => null]
but they both do the same thing. Any idea how I would go about removing just one out of the x possible parameters?
答案1
得分: 0
fullUrlWithoutQuery
使用 Arr::except()
来移除参数中提到的键。由于您的 architecture
键本身是一个数组,要从特定位置移除值,可以使用如下的点号表示法:
dd(Arr::except(['architecture' => ['Type1', 'Type2']], ['architecture.0']));
对于您的情况,假设您希望移除第 0
位置的元素,那么可以使用 ->fullUrlWithoutQuery('architecture.0')
。
英文:
fullUrlWithoutQuery
uses Arr::except()
to remove keys mentioned in the parameters. Since, your architecture
key is an array in itself, to remove value from any specific location, use the dot notation syntax like below:
<?php
dd(Arr::except(['architecture' => ['Type1', 'Type2']], ['architecture.0']));
For your case, let' say you wish to remove the 0th
location, then it will be ->fullUrlWithoutQuery('architecture.0')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论