我正在考虑实现类似http://www.databaseanswers.org/data_models/event_reservations/index.htm
的架构设计我需要显示考勤表,其中显示了活动的客户名称和席位。如何编写查询/查询,以便我可以轻松显示数据并在必要时进行更新?
答案 0 :(得分:0)
如果您使用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