Laravel 不允许使用补丁方法!是否有其他请求方法?
我一直在犯这个错误 错误Laravel 不允许使用补丁方法!是否有其他请求方法?,laravel,methods,request,axios,patch,Laravel,Methods,Request,Axios,Patch,我一直在犯这个错误 错误 public function update(Request $request, $id) { Cart::update($id, $request->quantity); session()->flash('success', 'Quantity was updated successfully'); return response()->json(['success' => true]); } 补丁htt
public function update(Request $request, $id)
{
Cart::update($id, $request->quantity);
session()->flash('success', 'Quantity was updated successfully');
return response()->json(['success' => true]);
}
补丁http://localhost/cart/027c91341fd5cf4d2579b49c4b6a90da 405(不允许使用方法)
我在某个地方读到服务器上没有启用补丁方法,我使用的是Apache 2.4.41。我试图通过mod_allowmethods模块找到一种方法来启用它,但无法编辑或修改该文件。在这一点上,我被困在任何帮助将不胜感激
下面是试图更新购物车数量的代码
HTML
<div>
<select class="quantity" data-id= "{{ $item->rowId }}">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">5</option>
</select>
</div>
车载控制器
public function update(Request $request, $id)
{
Cart::update($id, $request->quantity);
session()->flash('success', 'Quantity was updated successfully');
return response()->json(['success' => true]);
}
使用post方法并将修补程序作为数据发送
axios.post('/cart/${id}', {
quantity: this.value,
_method: 'patch',
_token: '{{ csrf_token() }}'
})
.then(function(response) {
windows.location.href = '{{ route('cart.index') }}'
})
.catch(function(error) {
console.log(error);
})
使用post方法并将修补程序作为数据发送
axios.post('/cart/${id}', {
quantity: this.value,
_method: 'patch',
_token: '{{ csrf_token() }}'
})
.then(function(response) {
windows.location.href = '{{ route('cart.index') }}'
})
.catch(function(error) {
console.log(error);
})
请尝试以下代码:
添加csrf令牌
<meta name="csrf-token" content="{{ csrf_token() }}">
请尝试以下代码:
添加csrf令牌
<meta name="csrf-token" content="{{ csrf_token() }}">
有两种可能性。1) 您正在缓存路由,并将其更新为自上次缓存以来的修补程序。您可以尝试
php-artisan-route:clear&&php-artisan-config:clear
。2) 您的nginx/apache配置正在阻止补丁方法。查看您的配置,看看它是否在任何地方被阻止。感谢您的响应,但我尝试清除路由缓存,配置缓存仍然是同一个错误,apache配置没有任何设置阻止它只链接到模块,我相信mod_allowmethods模块有设置,但无法编辑,是一个.SO文件类型。你发布的代码对我来说很好。这可能是apache的问题。有两种可能性。1) 您正在缓存路由,并将其更新为自上次缓存以来的修补程序。您可以尝试php-artisan-route:clear&&php-artisan-config:clear
。2) 您的nginx/apache配置正在阻止补丁方法。查看您的配置,看看它是否在任何地方被阻止。感谢您的响应,但我尝试清除路由缓存,配置缓存仍然是同一个错误,apache配置没有任何设置阻止它只链接到模块,我相信mod_allowmethods模块有设置,但无法编辑,是一个.SO文件类型。你发布的代码对我来说很好。这可能是apache的问题。感谢您的回复,但我在尝试此代码发布404(未找到)后出现此错误。您是否添加了\u方法:“补丁”
?是的,我添加了,与您发布的完全相同。感谢您的回复,但是我在尝试代码发布404(未找到)后出现此错误。您是否添加了\u方法:“补丁”
?是的,我添加了,与您发布的完全相同。