I am trying to get the time \"created_at\" for the last user activity,
I have the model User, and UserActivity.
I want to get the last user act
You should eagerload user activities at the same time then with subquery filter based on created_at. Call the latest to get last record and you should be good to go.
$latest_activites = User::with('activites')
->where("activites",function($query){
$query->where("created_at",">=",Carbon::now()->subDays(3));
})->latest()->get();