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 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答