Relations do not take parameters, you would need to query an existing relation:
// Machine.php
public function reading()
{
return $this->hasOne(Reading::class)->orderBy('date');
}
This relation is rather meaningless on its own (it will return the first reading for the given machine); but the real power comes from querying the relation, where we can determine which reading should be first:
$date = Carbon::createFromFormat('d-m-Y', $date)->format('Y-m-d');
Machine::with(['reading' => function ($query) use ($date) {
$query->where('date', '>=', $date);
}])->find($machineId);
Now you will have a Machine instance which has a reading property containing the nearest reading from $date