Reputation: 13
Sorry in advance for inappropriate question.I am a beginner in php and laravel. Wondering where i am doing mistake in the following code fragment.
$customer_vlan = Customer::select('vlan_id')->get();
$vlans = Vlans::where(function($query) use ($customer_vlan){
$query->where('id','!=',$customer_vlan);
})->get();
I have two tables in database."Customer" table has a column 'vlan_id'. In first query i am trying to fetch used vlan_id.
For second table "Vlans", column'id' holds all possible vlan. So i am trying to find which vlan's not used.
Upvotes: 1
Views: 40
Reputation: 493
You are trying to compare id with a collection. Then the result is all of the Vlans
.
$query->where('id','!=',$customer_vlan);
I think the best way to do this is loop through $customer_vlan
collection and push $customer_vlan[$i]->id
to an array. Then you can use this:
$query->whereNotIn('id', $arrayOfId);
Upvotes: 2