Skip to content
Advertisement

Laravel eloquent creating a WHERE condition if and only if the table column has a specific value

I am not sure if this is possible with Laravel eloquent, but I want to create an eloquent where the where condition would be based on the value of the current table column.

Something like this for illustration purposes:

JavaScript

column_a is part of the table column that I want to use. I could create 2 separate eloquent with their corresponding conditions and then merge them later but I dont want to go down that route if possible.

I thought of using ->when() but based on what I understood, ‘->when()’ is used for variable. Sorry if this is something basic but I dont really know how to proceed with this.

PS:

I also tried

JavaScript

But I am getting Object of class Closure could not be converted to string

Advertisement

Answer

I think what you want to do is this :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement