Laravel的`fullUrlWithoutQuery($keys)`移除所有参数。

huangapple go评论66阅读模式
英文:

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']));

Online Demo

For your case, let' say you wish to remove the 0th location, then it will be ->fullUrlWithoutQuery('architecture.0')

huangapple
  • 本文由 发表于 2023年5月29日 18:33:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356590.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定