laravel中collection的作用是什么

今天就跟大家聊聊有关laravel中collection的作用是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新新互联,凭借十多年的网站建设、成都网站设计经验,本着真心·诚心服务的企业理念服务于成都中小企业设计网站有上千家案例。做网站建设,选创新互联

pluck

public function getDeductCourse()
    {
        return TeacherFinanceLogModel::select(['order_id', 'period'])->where('type', 6)
            ->get()->pluck('period', 'order_id')->all();

    }

group map keyBy

public function getStudentCourseByUids($uids)
    {
        $studentCourse = $this->studentCourseModel
            ->select(['uid', 'grade_type', 'subject', 'period', 'old_period', 'period_total', 'finish_period', 'wait_period', 'total_free_period', 'free_period', 'wait_free_period'])
            ->whereIn('uid', $uids)
            ->get();

        return collect($studentCourse)->groupBy('uid')->map(function ($item) {
            return $item->keyBy(function ($value) {
                    return sprintf("%s-%s-%s", $value['uid'], $value['grade_type'], $value['subject']);
                })->toArray();
        })->toArray();
    }

filter

public function getRewardsAndPunishByUid($uids)
    {
        $rewardPunish = $this->courseRewardsModel
            ->select([
                "course.uid",
                "course.grade_type",
                "course.subject",
                "course.course_type",
                "course.period_type",
                "course.course_id",
                "course.tid",
                "course_rewards.s_rewards",
                "course_rewards.t_rewards",
                "course_rewards.s_option_status",
                "course_rewards.t_option_status"
            ])
            ->leftjoin("course", "course.course_id", "=", "course_rewards.course_id")
            ->whereIn('course.uid', $uids)
            ->where("course.course_type", 1)
            ->get();

        return collect($rewardPunish)->filter(function ($item) {
            return ($item->s_rewards == 1 || $item->s_rewards == -1) && $item->s_option_status != 1;
        })->groupBy('uid')->map(function ($item) {
            return [
                'reward_total' => $item->filter(function ($value) {
                    return $value->s_rewards == 1;
                })->sum('s_rewards'),
                'punish_total' => abs($item->filter(function ($value) {
                    return $value->s_rewards == -1;
                })->sum('s_rewards'))
            ];
        })->toArray();
    }

看完上述内容,你们对laravel中collection的作用是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。

网页题目:laravel中collection的作用是什么
本文地址:https://www.cdcxhl.com/article38/ihihpp.html

成都网站建设公司_创新互联,为您提供虚拟主机网站制作移动网站建设标签优化网站内链App设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站建设