mercredi 27 juin 2018

Laravel 3 Table Relationship

Can anyone help me how to display the product name? I have productquantity stored in my purchase record and now I want to display the product name in productquantity record.

I have 3 Tables

Purchaserecord - id - purchasenumber - prodquantityid

Productquantities - id - prod_id

Product - id - productname

I have this in my controller

public function createpurchase(Request $request)
{
        $purchasenumber = $request->purchasenumber;
        $dataPurchaseRecord = Purchaserecord::where('purchasenumber','=',$purchasenumber)->with('productquantity')->get();
        return view('admin.createpurchase',compact('purchasenumber', 'dataPurchaseRecord')); 

}

In my view

@forelse($dataPurchaseRecord as $Request)
              <tr>
                <td> <a class="name"></a></td>
                <td><em class="productprice"></em>  </td>
                <td style="width:100px;" class="td-actions"><a href="javascript:;" class="delete-modal btn btn-mini btn-danger" data-id="" ><i class="icon-minus"> </i>Remove</a> </td>
               </tr>
               @empty
               <tr><td colspan='4'><em>No Data</em></td></tr>
              @endforelse

in my model

 public function product()
{
    return $this->belongsTO('App\Product', 'prodquantityid', 'id');
}

this should be display the product name instead of the id How can I build the model and view on this? Please help.

Thank you



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ty3Q9c
via IFTTT

Aucun commentaire:

Enregistrer un commentaire