7 months ago

joins and where clause?

Posted 7 months ago by zaster

CostItem hasOne POItem


public function create(Request $request)
        //Get the vendor_company_id and get the related cost_items       
        $vendor_company_id = $request['vendor_company'];        

        $cost_items = CostItem::where('vendor_company_id', $vendor_company_id)                        

            $po_item = new POItem();
            $po_item->cost_item_id = $cost_item->id;
            $po_item->po_id = $cost_item->po_id;
            $po_item->qty = $cost_item->qty;
            $po_item->rate = $cost_item->rate;
            $po_item->description = $cost_item->description;
        return view('employees.poitems.create', compact('cost_items'));

What i need is to get the po_item_ids related to cost_item_ids

to display something like this


@foreach($po_items as $po_item)

<input type="text" class="form-control" name="vendor_name" id="vendor_name" 
value="{{$po_item->cost_item->vendor_company->name}}" readonly>   

<input type="text" class="form-control" name="item" id="item"


Please assume that all relationships are defined

Please sign in or create an account to participate in this conversation.