I have a belongsToMany association between Appointment and Status models. The below query returns all of the statuses and I want to alter it to pull the last status assigned to the appointment.
$query = Appointment::query();
$query->with('statuses');
$query->with("agent");
$query->with("instruction_type");
$query->with("sign_up_customer");
$table = Datatables::of($query);
I have tried altering the query with this but it doesn't work.
$query->with('statuses')->latest();
via showFocus