-
-
Notifications
You must be signed in to change notification settings - Fork 127
Closed
Labels
Description
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()
Peter-Krebs and JoaoPedroAS51