1

Given I have this simple query:

$builder = User::select(DB::raw('users.age as age, users.restrict as restrict'))
               ->whereBetween("user.id",$id)
               ->get();

Is there any way to get users where age is lower than restrict column ?

2 Answers 2

1

Since both age and restrict are columns, use the whereColumn() method. Also, it looks like you want to get only records with IDs that are in $ids array. So, use whereIn():

User::whereColumn('age', '<', 'restrict')->whereIn('id', $ids)->get();
Sign up to request clarification or add additional context in comments.

Comments

0

This ->where("user_id", $id) returns only one user! does not it ?

$users = DB::table('users')->whereBetween("id",$ids)
                           ->where("age",'<','restrict')->get();

Or

$users = User::where("age",'<','restrict')->whereBetween("id",$ids)->get();

1 Comment

my bad that should be whereBetween some array of id's, I tried that unknown column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.