vendredi 2 octobre 2015

Get result from 2 pivot tables [Laravel 5]

I have some query with 2 replations and it look like this:

Project::with(['comments' => function($q) {
                        if ($this->what == 0) {
                            $q->where('project_id', $this->id)->where('order', $this->what)->orderBy('comments.id', 'DESC')
                                    ->skip($this->commentsPerPage * ($this->page - 1))->take($this->commentsPerPage);
                        } else {
                            $q->where('project_id', $this->id)
                                    ->where('order', $this->what)->orderBy('comments.id', 'DESC');
                        }
                    }, 'groups' => function($q) {
                        $q->where('project_group.project_id', $this->id)->where('project_group.user_id', $this->userID);
                    }])->where('id', $this->id)->get();

Problem is with groups part it should limit to get only result if this questy true: $q->where('project_group.project_id', $this->id)->where('project_group.user_id', $this->userID); But in my case I will get result even if my query not true...

I would appreciate if someone can help?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire