简体   繁体   中英

laravel - how to set relation with hasManyThrough?

I have problem with relation of laravel in this case.

One event has many event dates.

One event date has many tickets.

One ticket has many slots. User will book slot and save in booking table.

How can i get list of event dates have list of tickets and total booking of every ticket ?

In Event model i has :

return $this->hasMany('App\EventTicket', 'event_date_id');

Please help me improve it to get right data ?

1) How can I get list of event dates to have list of tickets?

you can make hasManyThrough relation for that. In EventDates model make relation as tickes with hasManyThrough .

Now through event dates, you will get all the tickets for that day.

2) total booking of every ticket

after make hasManyThrough you can use withCount('tickes') with this, you'll get the booking total count.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM