Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

itamelions's avatar

Laravel many to many Query

I have a many to many associations on Vendors and Orders models whenever I try to query the vendor Id I get

Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, int given

My code is

public function orders()
    {
        $vendor_id = Auth::guard('vendor')->user()->id;
        
        $orders = Order::whereHas('vendors', function($vendor) use($vendor_id){
            $vendor->whereIn('id', $vendor_id);
        })->orderBy('created_at', 'desc')->get();

       
        return $orders;
}

Please, how do I go about fixing this?

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

WhereIn expects an array of values not a single value

Please or to participate in this conversation.