-2

I write one query which will return true or false by using exists() function in laravel like this

$a=$item->conditions()->exists();

The above query works fine ,now i want to extend the query with where condition that will check weather the status column should equal to the active for that i am writing the following code but it's throwing an error like Call to a member function where() on boolean ,please help me to extend the query for writing a where condition.

$a=$item->conditions()->exists()->where('status','=','active');

Note:- conditions() -->returns an ID from the model

Code cracker
  • 316
  • 1
  • 5
  • 20

1 Answers1

0

Well you have to write the where condition before call exists() method. So it's gonna be like this:

$a = $item->conditions()->where('status','=','active')->exists();
Tra Lee
  • 113
  • 1
  • 8
  • i have one more doubt it will check both the id and status na in condition table , that means it won't effect previous my query ryt..? – Code cracker Oct 14 '21 at 09:39
  • Hmm, idk what's in your `condition()` but you writing all condition in a same statement so the answer is no. It will effect your previous query. – Tra Lee Oct 14 '21 at 09:55