If I use created_at is there some way to pick the oldest one in the scope?
I like the flag idea but I can't implement it based on my actual use case and how dynamically the data changes. Thanks though!
For another example maybe a guest can make a reservation, this reservation has many service_dates, and each service_date has a 'room_number' column.
I'd like to return all reservations where the guests first service_date is in room_number 101. But what I'm getting back (and that I don't want) is all reservations where any of the service_dates were in room_number 101.
public function scopeFilterByRoomNumber($query, $room_number)
{
$query->whereHas('service_dates', function($q) use ($room_number) {
$q->where('room_numer', '=', '101');
});
}
I don't want guests whose room_number was 101 on the 2nd night or 3rd night, just their first night. As an example.