User can apply many times to single order. The last apply is the one I want. My code:
$users = User::whereHas('applies', function ($query) use ($order_id){
$query->where('order_id', $order_id);
})->with(['applies' => function($query) use ($order_id){
$query->orderBy('id', 'desc')->where('order_id', $order_id)->first();
}])->paginate($request->perPage);
This limit the number of applies only in the last user, the other applies records are empty. Removing first() from with() shows all applies in all users. How is that? Please help.
I've tried limit(1), take(1)->get(), take(1), but it also fails.