drmet46444 2015-09-23 13:35
浏览 8

抵消不与Laravel关系[Laravel 5]

I am trying to take skip and take elements... Here is my try:

public function orderWhat($what){
           $this->what = $what;
           //QUERY FOR GROUPS AND PRODJECT_GROUP
           $userCondition = function($q){
                        $q->where('user_id',Auth::id())->where('project_id',$this->id)->take(10)->skip(10);
                    };

           //QUERY FOR COMMENTS AND PROJECT_COMMENT     
           $commentsCondition = function($q){
                        $q->where('project_id',$this->id)->where('order',$this->what)->orderBy('comment.id', 'DESC')->take(10)->skip(10);
                    };

                    $limit = function($q){
                        $q->take(10);
                    };
           //RETURN PROJECT WITH COMMENTS        
           $results = Project::with(['comments' => $commentsCondition,'groups' => $userCondition])
                                ->whereHas('groups', $userCondition)
                                ->whereHas('comments', $commentsCondition)

                                ->get();
           return $results;
       }

This will result with this query, but I will not get any result...

SQL: select * from projects where (select count() from groups inner join project_group on groups.id = project_group.group_id where project_group.project_id = projects.id and user_id = 1 and project_id = 1 limit 10 offset 10) >= 1 and (select count() from comments inner join project_comment on comments.id = project_comment.comment_id where project_comment.project_id = projects.id and project_id = 1 and order = 0 order by comment.id desc limit 10 offset 10) >= 1

If I remove offset it will just take fist 10 posts....

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)