Closed PHPieter closed 1 year ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I'm assuming using the when() function is a bit too painful here?
The when function would not provide the expected results because in this case it is not about user input but about a column that can be null
or can have an id
. Therefore we need the where
query. The When
method would work if you would know upfront if the result should be a record where expiration_date
is null
or an id
.
At this moment i think the solution above is the most clean one, but not in line with the current flow.
When doesn't need a user input, sadly the docs on Laravel don't explain this clearly, the following is a perfectly valid way of using when()
return User::query()
->when('email_verified_at == null', function ($query) {
Do Something Here
})
This may help you in simplifying the code above, which may make it a little easier to document/others to adopt!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I needed a more complex than standard query and suddenly the searchability of my table was broken. Wen i do a query dump, i see the search query is only added to the orWhere part of the query. Therefore the first part of the always stays the same and therefore the searchability is not working. The query below broke the searchability.
I could not think of a solution which is in line of the current
->searchable()
. The answer below is a potential fix where i think the private methods should go in a trait (MakeSearchableTrait).