<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class ItemVendor extends Model
{
    protected $table = 'item_purchase_request_vendor';

    public static function getVendorItems($vendor_id = null ,  $purchase_request_id  = null )
    {
       $purchase_request_items = PurchaseRequest::find($purchase_request_id)
        ->item->pluck('item_id')->toArray();

        $vendor_items = ItemVendor::where('purchase_request_vendor_id' ,  $vendor_id)
        ->whereIn('item_id' , $purchase_request_items )->pluck('item_id')->toArray();

        return ItemPurchaseRequest::where('purchase_request_id' ,  $purchase_request_id)
        ->whereIn('item_id' , $vendor_items )
        ->get();
 }

}
