Friday, March 17, 2017

How do I "join columns" so I can call $product->location

I have the following tables

Events

    id
    name
    start_date
    end_date

EventLineItems (belongs to event & product)

    id
    event_id
    product_id
    quantity

Products

    id
    name
    quantity
    rack
    section
    level
    position

Currently my blade for events.show file looks like this

@foreach ($event->lineitems as $item)
  <tr>
   <td></td>
   <td></td>
   <td></a></td>
   <td></td>
   <td> -  -  - </td>  
  </tr>
 @endforeach

I want to be able to call $item->product->location in my view instead of each field individually. I think this would go in my model as a function but not sure how or what to google.

For simplistic purposes think (invoice, lineitems, products)



via DevJustin

Advertisement