Replies: 1 comment
-
I think that method is very nice if added, it will shorten the code quite a bit, and it looks nicer |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I really understand the use of where combined with column names in the database, like the example below:
The query will execute SQL query
WHERE `name` = 'John Doe'
, so, I have an idea to handle the case if the user searches for User name with an empty value but wants to retrieve all data,I am trying to use the
scope
andwhen
combination in Laravel for the purpose that if the value is empty it will not be processed, I have made a sample below:The implementation is as follows:
The first condition, if the user fills in the
name
query, User will appear with the name that matches the filled query, however, if the query is null/false, then it will skipWHERE
clauses.Wouldn't it be nice if
when{ColumnName}
was provided by default by Laravel exactly like thewhere{ColumnName}
concept? I think it will be more dynamic for the above case, thanks.Beta Was this translation helpful? Give feedback.
All reactions