Laravel - How to write Multiple conditions in where clause?

Actually my query is:

SELECT * FROM company WHERE status<>$status AND type=$b1 AND type=$b2

How to convert this in laravel?

I did this in laravel but it is not working:

$data['Company'] = DB::table('company')->where([["status","<>",$status], ["type","=",$b1],["type","=",$b2]])->get();

Please help me!

Upvotes: 2

Views: 2428

Answers (4)

The whereIn method verifies that a given column's value is contained within the given array:

$data['Company'] = DB::table('company') ->where('status','<>',$status) ->whereIn('type',['$b1','$b2') ->get();

Upvotes: 1

Sletheren
Sletheren

Reputation: 2486

Try this:

\App\Company::where('status','!=',$status)->where('type',$b1)->where('type',$b2)->get();

Upvotes: 1

Yusuf Eka Sayogana
Yusuf Eka Sayogana

Reputation: 401

You should use where method in 1 condition

$data['Company'] = DB::table('company')->where('status','<>',$status)->where('t‌​ype',$b1)->where('ty‌​pe',$b2)->get();

Upvotes: 1

Kuldeep Mishra
Kuldeep Mishra

Reputation: 4050

$data['company'] = DB::table('company')->where('status',$status)->where('type',$b1)->where('type',$b2)->get();

Upvotes: 1

Related Questions