I am working on Laravel 5.7 and VueJs 2....
I am working on invoice application, i need to make relationship between my tables:
Table 1: VendorsTable
Table 2: TicketInvoiceTable
Table 3: TicketInvoiceItemsTable
My TicketInvoice Model
public function vendor(){
return $this->belongsTo('App\Vendor');
}
public function ticketInvoiceItems(){
return $this->hasMany('App\TicketInvoiceItems');
}
My TicketInvoiceItems Model
public function ticketInvoice(){
return $this->belongsTo('App\TicketInvoice');
}
My Vendor Model
public function ticketInvoices(){
return $this->hasMany('App\TicketInvoice');
}
I also assign foreign key in TicketInvoice and TicketInvoiceItems Table:
//CreateTicketInvoiceTable
$table->foreign('vendor_id')->references('id')->on('vendors');
//CreateTicketInvoiceItemsTable
$table->foreign('ticket_invoice_id')->references('id')->on('ticket_invoices');
I successfully seed Faker data in all tables.
Now i need to display the Vendor's Name in my Vue template.
I dont know how to do this, here is my Vue code:
<tr>
<th>Invoice No.</th>
<th>Issued Vendor Name</th>
<th>Invoice Date</th>
<th>Total Amount</th>
</tr>
<tr v-for="ticketInvoice in ticketInvoices" :key="ticketInvoice.id">
<td>{{ ticketInvoice.ticket_invoice_no }}</td>
<td>{{ ticketInvoice.vendor_name}}</td> //NEED VENDOR NAME HERE
<td>{{ ticketInvoice.ticket_invoice_date }}</td>
<td>{{ ticketInvoice.ticket_invoice_grand_total }}</td>
</tr>
Script
<script>
export default {
data() {
return {
ticketInvoices: {},
form: new Form({ //ALL FIELDS IN TICKET INVOICE TABLE
id: "",
vendor_id: "",
ticket_invoice_no: "",
ticket_invoice_date: "",
ticket_invoice_fares_total: "",
ticket_invoice_taxes_grand_total: "",
ticket_invoice_grand_total: "",
ticket_invoice_grand_total_words: "",
ticket_invoice_terms: "",
})
};
},
methods: {
loadTicketInvoices() {
axios.get("api/ticket-invoice").then(({ data }) => (this.ticketInvoices = data.data));
},
},
};
</script>
FROM THIS RESULT, i get data which is in TicketInvoiceTable and tried some other things but no success.