I'm working on a Laravel project where a Stay can either reference a Vehicle or store vehicle information directly. This avoids creating a Vehicle for one-time stays, as most vehicles won't return.
My structure example
Stay:
vehicle_id: id foreign nullable # null if other_fields
vehicle_plate: string nullable # null if vehicle_id
vehicle_type_id: id foreign nullable # null if vehicle_id
Vehicle:
plate: string unique
vehicle_type_id: id foreign
VehicleType:
name: string unique
I want a way to access $stay->vehicleType from a Stay, whether it's from the associated Vehicle or directly from the Stay information (only one of them will be available, I cannot have Stay with both vehicle_type_id and vehicle_id). When I create a Stay, I'll fill vehicle_id leaving the other fiels null and vice-versa.