Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add when() method #219

Closed
ajcastro opened this issue Sep 15, 2021 · 1 comment
Closed

Add when() method #219

ajcastro opened this issue Sep 15, 2021 · 1 comment
Labels
enhancement New feature or request released

Comments

@ajcastro
Copy link

ajcastro commented Sep 15, 2021

Please, can we add when() method for conditional clause to make code more readable/concise.
https://laravel.com/docs/8.x/queries#conditional-clauses

I saw a code somewhere:

      const query = User.page(params.page || 1)
        .include('avatar')
        .orderBy(params.sort)

      if (params.search) {
        query.where('search', params.search)
      }

      const result = await query.params({ limit: 20 }).get()

Would be re-written to:

      const result = await User.page(params.page || 1)
        .include('avatar')
        .orderBy(params.sort)
        .when(params.search, (query, search) => query.where('search', search))
        .params({ limit: 20 })
        .get()
@robsontenorio robsontenorio added the enhancement New feature or request label May 24, 2022
@github-actions
Copy link

github-actions bot commented Jul 5, 2022

🎉 This issue has been resolved in version 1.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

2 participants