我正在考虑实现这样的架构设计http://www.databaseanswers.org/data_models/event_reservations/index.htm

我将需要显示一个考勤表,其中显示了活动的客户名称和席位。如何编写查询/查询,以便可以轻松显示数据并在必要时进行更新?

最佳答案

如果您使用的是Eloquent并且模型设置正确,则查询示例如下:

$reservations = CustomerBooking::where('event_id', $id)
    ->with('event', 'customer', 'seat')->get();


在视图中:

Event Name: {{ $reservations->event->event_name->first() }} at {{ $reservations->event->venue->venue_name->first() }}
{{ $reservations->event->event_start_date->first() }} to {{ $reservations->event->event_end_date->first() }}


客户资料:

@foreach($reservations as $reservation)
Name: {{ $reservation->customer->customer_name }}
Seat: {{ $reservation->seat->seat_number }}
@endforeach

10-05 19:58