duanjingwei7239 2015-05-11 22:31
浏览 8
已采纳

如果在列表中选择了超过2列

I have this eloquent model query

public function getemployee(){
    $id = $_POST['id'];
    $employees = mot_users::where("branch_no", $id)->lists('user_no', 'lastname', 'firstname');
    return response()->json(['success' => true, 'employees' => $employees]);
}

the problem is this "->lists();" can only handle 2 columns which sent as a json response (seen through console, only 2 selected columns out of 3 is sent). How can I send 3 columns or more than 2 columns in the "->list()" or is there any alternative eloquent model query other than using "->list()" if its impossible?

  • 写回答

1条回答 默认 最新

  • dquv73115 2015-05-12 08:06
    关注

    To do this, just do a

    $employees = mot_users::where("branch_no", $id)->get(array('user_no','lastname','firstname'))->toArray();
    

    That should do the trick.

    Note that if your model object has a relationship and this column relationship isn't part of what you try to ->get you can't get an error.

    Note 2 that here you're using the good ol' $_POST, you should consider using the proper Request object as seen in the doc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题