2016-05-25 10:04

Laravel - 将id作为参数传递,但路由获取密钥,而不是值


So I am experiencing a really strange problem. I am passing my parameters like this:

<form action="{{ route('deleteCustomerCartItem', ['product_id', $cartItem['product']->id, 'size' => $cartItem['size']]) }}" method="post">

I am printing the $cartItem['product']->id inside my cart page and it prints the valid id. However when I pass it and var_dump it, I get string(10) "product_id". I noticed that my route doesn't get the actual id but it gets 'product_id'. Here is my route:

Route::post('/cart/delete/{product_id}/{size?}', [
'uses' => 'CartController@deleteCustomerItem',
'as' => 'deleteCustomerCartItem']);

Here is the url I get from this route: enter image description here

product_id must be 1 and S is the $cartItem['size']. I don't know why this happens or why it gets '?1' at the end.

I need to get the value of product_id not the key. Can someone explain why this happens and how can I fix it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douhezhang8932 douhezhang8932 5年前
    ['product_id' => $cartItem['product']->id, 'size' => $cartItem['size']]
    // Note the use of => here instead of ,
    点赞 评论 复制链接分享