Skip to content

Query builder : simulate switch using when #44999

Answered by teikun-86
pildit asked this question in Q&A
Discussion options

You must be logged in to vote

Put the ->DontBelongsToCompany() as the third parameter on ->when() like:

...
->when($companyId, function ($query, $companyId) {
    return $query->Company($companyId);
}, function ($query) use ($excludeCompanyId) {
    return $query->DontBelongsToCompany($excludeCompanyId);
})
...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pildit
Comment options

Answer selected by pildit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants