0

Help me again.

I have this in my model

public function quantity()
    {
        return $this->hasMany('App\Productquantity', 'prod_id', 'id');
    }

and I want to get the branch name of each product quantity so the productquantity table has field of branch_id.

How can I display the branch name in branch table?

@forelse($Productquantity->quantity as $dataQuantity)
<tr class="item{{$dataQuantity->id}}">
<td align="center" style="text-align:center" width="100px"> <a href="#" class="avatar"><img src="{{ asset('productimg') }}/{{$dataQuantity->pic}}" width="50px"/></a> </td>
<td style="width:100px;"> {{$Productquantity->product_name}}</td>
<td>{{$dataQuantity->quantity}}</td>
<td>{{$dataQuantity->price}}</td>
<td>{{$dataQuantity->branch_id}}</td>
<td style="width:100px;" class="td-actions"><a href="javascript:;" class="edit-modal btn btn-mini btn-info" data-id="{{$dataQuantity->id}}" ><i class="icon-plus"> </i> Add Stocks</a> </td>
</tr>  

@empty
<tr>
<td colspan="5"> <em>No Data</em></td>
</tr>

@endforelse 

this {{$dataQuantity->branch_id}} should be displayed the name instead of the branch Id.. Please help.

1 Answer 1

1

I would say you need a relationship on your Productquantity model to your branch.

Something like

public function branch()
{
    $this->hasOne('App\Branch', 'branch_id');
}

and then you could do this:

$dataQuantity->branch->branch_name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.