doupo2633 2016-05-25 10:04
浏览 110
已采纳

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?

  • 写回答

1条回答 默认 最新

  • douhezhang8932 2016-05-25 10:07
    关注
    ['product_id' => $cartItem['product']->id, 'size' => $cartItem['size']]
    
                  ^
                  |
    // Note the use of => here instead of ,
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?