Conditional query chain


How can I implement below PHP/Laravel code in adonis js?
Sorry if title is not suitable for the content of this question.

$user = App\User::where('active', 1);
if( $request->has('foo') )
    $user->where('foo', 'bar');




The title is suitable and infact the body of the question is redundant.

What you are trying to achieve is possible, but expecting that you will share a PHP snippet and someone will translate that to Javascript or Adonis specific code is not a great idea.

Please read the docs here

Also, make sure to construct questions around Adonis and do not share snippets for translation


Actually I’m not that lazy guy to ask others translate a language snippet to another, sorry if my question meant that to you.

I read the docs before asking this question. I am in a project and yeah I’ve read the docs many times :slight_smile: , but yet I don’t know how to implement the PHP code I posted.