Djozeph
Djozeph

Reputation: 25

Laravel comparing Query result with variable

I have these two variables

$categories = Relation::select('child_id', 'distance')
->where('parent_id', $request->who)
->orderBy('distance', 'asc')
->get();

$request->newParent; 

Is there any way to check if my query result($categories) contains id same as $request->newParent without making another database query.

Upvotes: 0

Views: 437

Answers (1)

Rahul Jat
Rahul Jat

Reputation: 706

Try this

$categories = Relation::with('newParent')
 ->select('parent_id','child_id', 'distance')->where('parent_id', 
$request->newParent)->orderBy('distance', 'asc')->get();

return $categories; 

Upvotes: 1

Related Questions