Skip to content
Advertisement

How to use where condition in if statement which is already written in codeigniter

I have got a situation where the $user_id parameter is optional and I used to do this in codeigniter in the way written below. But I am not able to figure it out, How can I write this query in laravel’s eloquent and query builder as well. Any help is much appreciated.

Thanks

Advertisement

Answer

Using Eloquent:

Using Query Builder:

Replace the ModelName with one defined for the table users.

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