laravel 循环中子元素使用&符号嵌入到父级,经典版

laravel 循环中子元素使用&符号嵌入到父级,经典版

   /**ajax 获取企业名称
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     * @author lxw
     */
    public function getCompanyName( Request $request )
    {
        $keyword = $request->query->get('q', '');

        $allCompany = Company::query();
        $allCompany = $allCompany->select('id', 'username');
        if ( $keyword ) {
            $allCompany = $allCompany->where('username', 'like', '%' . $keyword . '%');
        }
        $allCompany = $allCompany->orderBy('created_at', 'desc');
        $allCompany = $allCompany->limit(5);
        $allCompany = $allCompany->get();
        if ( empty($allCompany) ) {
            return response()->json(['status' => 500, 'data' => new \ArrayObject(), 'msg' => '搜索关键字不存在']);
        }
        $data = [];
        foreach ( $allCompany->toArray() as $item ) {
            $data[] = [
                'id' => $item['id'],
                'text' => $item['username'],
            ];
        }
        return response()->json(['status' => 200, 'data' => $data, 'msg' => '搜索成功']);
    }

    /**ajax请求该企业下的所有楼宇
     * 执行中的显示其他订单已开通
     *
     * @param $companyId
     *
     * @return \Illuminate\Http\JsonResponse
     * @author lxw
     */
    public function getCompanyBuildings( $companyId )
    {
        //该企业下已经被创建过订单且处于执行中的的楼宇id
        $doingBuilds = BuildingPayment::query()
            ->where('company_id', $companyId)
            ->whereDate('duetime', '>', date('Y-m-d', time()))
            ->groupBy('building_id')
            ->get(['building_id']);

        $doingBuildArr = $doingBuilds ? $doingBuilds->toArray() : [];
        $doingBuildIds = array_column($doingBuildArr, 'building_id');

        //该企业下所有的楼宇
        $allBuildings = Building::query()
            ->where('company_id', $companyId)
            ->orderBy('sort', 'asc')
            ->get(['id', 'name']);
        $allBuildings = $allBuildings ? $allBuildings->toArray() : [];
        foreach ( $allBuildings as &$building ) {
            if( in_array($building['id'], $doingBuildIds)){
                $building['isPayment'] = true;
            }else{
                $building['isPayment'] = false;
            }
        }

        return response()->json(['status' => 200, 'data' => $allBuildings, 'msg' => '搜索成功']);
    }

  

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/112365.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • php中的<?= ?>替换<?php echo ?>

    php中的<?= ?>替换<?php echo ?>

    2021年11月4日
    48
  • datax(16):源码解读AbstractReporter

    datax(16):源码解读AbstractReporter之前介绍了通信类communication,容器类container,communication的收集类collector,今天再看一个报告类Reporter;一、概述AbstractReporter主要作用:Reporter的主要功能是将收集到的信息上报给上级主要方法:reportTGCommunication(汇报TG的communication信息给上级),reportJobCommunication(汇报job的communication信息给上级)二、族谱族谱里面目前只有父子.

    2022年5月16日
    40
  • 解决CentOS7虚拟机无法上网并设置CentOS7虚拟机使用静态IP上网

    解决CentOS7虚拟机无法上网并设置CentOS7虚拟机使用静态IP上网最近在VMware虚拟机里玩Centos,装好后发现上不了网。经过一番艰辛的折腾,终于找到出解决问题的方法了。最终的效果是无论是ping内网IP还是ping外网ip,都能正常ping通。方法四步走:第一步,我们进入/etc/sysconfig/network-scripts目录,查看该目录有没有形如ifcfg-XXX的文件:如果你看不到以ifcfg-打头的文件(ifcfg-lo除外),…

    2022年5月12日
    36
  • handlersocket原理和性能测试[通俗易懂]

    handlersocket原理和性能测试[通俗易懂]1.handlersocket原理很久以前做的测试了,今天只是为了留个存底的地方,所以拿上来,有很多不严谨的地方望大家多多包涵,也可以留言更正我的错误,谢谢!都说handlersocket速度不是

    2022年7月2日
    17
  • 模型调参:分步骤的提升模型的精度

    模型调参:分步骤的提升模型的精度

    2021年11月21日
    42
  • ntp服务器地址是什么协议,ntp服务器地址的介绍与解释

    ntp服务器地址是什么协议,ntp服务器地址的介绍与解释ntp服务器地址的介绍与解释分类:云服务资讯编辑:浏览量:1002021-07-2314:43:16NTP属于运用层协议(依据UDP传输,运用的端口号为123),用来同步网络中分布式时间服务器和客户端之间的时间,使网络中的设备供应依据一起时间的运用成为可能。时间服务器和客户端是相对的。供应时间规范的设备为时间服务器,接收时间服务的设备为时间客户端。设备运转NTP之后,通过沟通NTP报文,既可以作…

    2022年5月1日
    46

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号