mardi 12 juillet 2016

How can I access this value in a pivot table (Laravel)?

I'm putting together a simple shopping cart system, using Laravel and Vue.js, to sell photos. Each photo comes in a range of sizes, with the price of each size being different.

I have the following tables:

Photos
 - id
 - title

Sizes
 - id
 - dimensions

Photos_Sizes
 - id
 - photo_id
 - size_id
 - price

I'm using Vue.js to make API calls to my cart controller to manipulate the cart. It passes the photo_id and size_id when the user clicks the Add to Basket button. Naturally I want to grab the price of a selected item from the database rather than client side to prevent any cheekiness, and that naturally means querying the pivot table.

My question is, using the two ids passed to the controller, how can I access the correct price value in the pivot table?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire