Assume a following example:
I got table of cars, their owners and a table of their types.
table cars: id, owner_id, type_id
table types: name, description
I want to get all types, whose id is NOT in type_id in table cars AND their owner_id IS 1.
I pass owner from the view and I tried the following:
public function show(Owner $owner)
{
$cartypes =CarTypes::all()->whereNotIn('id', function($query) { $query->table('cars')->select('type_id')->where('owner_id', '=', $owner->id); })->get();
return view('sections.cars.show',compact('owner','cartypes'));
}
But get Error: Method Illuminate\Database\Query\Builder::table does not exist.
Is my query fine? Can someone help me fix my query to get desired result?