dongzhuo7291 2017-12-08 17:36 采纳率: 100%
浏览 44
已采纳

php - Laravel搜索控制器

I am trying to make Laravel Search and stuck at point of handling POST data as an array in Eloquent way

HTML Form is as

<form>
    <select name="hidArray[]">
       <option name="test">Test</option>
       <option name="test2">Test2</option>
    </select>
</form>

Now, this input has been initialized as Bootstrap Multiselect

When i get input as POST request then it has been represented as an array like as below and which is expetced

array:2 [▼
0 => "test"
1 => "test2"
]

Now, i want to form Eloquent query to get results from database.

I tried like as below:

if($request->has('hidArray')){
      $profile->whereIn('hidArray', $request->input('hidArray'));
}

But i think, this way it is not working. Is there any other way i can perform this operation?

  • 写回答

1条回答 默认 最新

  • doutan5724 2017-12-08 17:43
    关注

    I don't have exact idea what are you upto but according to what I understood.

    You are trying to do something like:

    $profile = ModelName::where('user_id',$id);
    
    if($request->has('hidArray')){
          $profile = $profile->whereIn('hidArray', $request->input('hidArray'));
    }
    
    $profile = $profile->get();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao