Javascript Laravel阵列$request->;全部()为空
我和拉威尔在一辆购物车上工作 我有: 路线:Javascript Laravel阵列$request->;全部()为空,javascript,php,ajax,laravel,axios,Javascript,Php,Ajax,Laravel,Axios,我和拉威尔在一辆购物车上工作 我有: 路线: Route::post('/panier/ajouter', 'CartController@store')->name('cart.store'); Route::patch('/panier/{product}', 'CartController@update')->name('cart.update'); 视图: <table class="table" id="table-shoppingcart">
Route::post('/panier/ajouter', 'CartController@store')->name('cart.store');
Route::patch('/panier/{product}', 'CartController@update')->name('cart.update');
视图:
<table class="table" id="table-shoppingcart">
<thead>
<tr>
<th class="text-center" id="item-title-shoppingcart"></th>
<th class="text-center" id="size-title-shoppingcart">Taille</th>
<th class="text-center" id="quantity-title-shoppingcart">Quantité</th>
<th class="text-center" id="price-title-shoppingcart">Prix</th>
{{-- <th class="text-center" id="delete-title-shoppingcart"></th> --}}
</tr>
</thead>
<tbody>
@foreach (Cart::content() as $product)
<tr>
<th><img class="text-center item-content-shoppingcart" src="{{ $product->model->image }}"></th>
<td class="text-center td-table-shoppingcart size-content-shoppingcart">S</td>
<td class="td-table-shoppingcart quantity-content-shoppingcart">
<select name="quantity" class="custom-select text-center quantity" id="quantity" data-id="{{ $product->rowId }}">
@for ($i = 0; $i < 5 + 1 ; $i++)
<option id="quantity-option" {{ $product->qty == $i ? 'selected' : '' }}>{{ $i }}</option>
@endfor
</select>
</td>
<td class="text-center td-table-shoppingcart price-content-shoppingcart">{{ getPrice($product->subtotal()) }}</td>
</tr>
@endforeach
</tbody>
</table>
我需要获取控制器中的数量,因此我尝试:
public function update(Request $request)
{
$data = $request->json()->all();
Log::info($data);
return response()->json(['success' => 'Cart Quantity Has Been Updated']);
}
但当我尝试获取$data值时,我的数组是空的,如日志中所示:
[2020-02-22 10:49:46] local.INFO: array ()
我试图改变:
$data = $request->json()->all();
到
但同样的问题
你知道吗
谢谢 Laravel通过
PUT/PATCH/DELETE
etc请求作弊。这些需要是POST
请求,并将额外变量“\u method”
设置为请求类型(例如PATCH
是否可以添加路由文件?哦,是的,对不起!我不认为是因为axios.patch现在工作正常,所以我尝试了这个。同样的错误,但我在数组中看到的是row_方法,而不是数量。因此,我尝试将数量:this.value更改为数量:5以进行测试。现在我得到了行的数量。所以这个问题就是数量:ajax请求中的this.value。你有什么想法吗?这是指JS中的局部范围。因为您使用的是Jquery,所以我看不出使用这个
有什么意义。您需要将事件注入到您的change函数中,然后从中获得值。如果需要,请告诉我您是否需要post-it-answerNow它正在工作,但我的更改仅在第一次工作?使用$('body')。on('change','#quantity',function(){…})代码>相反,你是老板!!只是当我的购物车中有不止一种产品时,问题就来了。当我更改第一个产品的数量时,第二个产品的数量也会更改。如何解决此问题?很高兴能提供帮助,如果此答案解决了您的问题,请单击答案旁边的复选标记将其标记为已接受。
$data = $request->json()->all();
$data = $request->all();