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 activity and check if the last activity of this user is 3 days to send notification,
User.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
public function activites()
{
return $this->hasMany(Activty::class);
}
}
Activity.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Activity extends Model
{
function function user(){
return $this->belongsTo(User::class);
}
}
Controller
$latest_activites = User::whereHas("activites",function($query){
$query->where("created_at",">=",Carbon::now()->subDays(3));
});
$latest_activites = $latest_activites->get();