'integer', 'target_id' => 'integer', 'target_author' => 'integer', ]; /** * Relationship: the member who took the action. * * Only meaningful while their account exists — a deleted actor leaves the * id behind on the row, which is what keeps the history honest. */ public function actor() { return $this->belongsTo(User::class, 'actor_id', 'ID'); } /** * Everything recorded against one topic or comment, newest first. */ public static function forTarget(string $targetType, int $targetId) { return static::where('target_type', $targetType) ->where('target_id', $targetId) ->orderBy('created_at') ->desc() ->get(); } /** * Everything one member has done, newest first. */ public static function byActor(int $actorId, int $limit = 50) { return static::where('actor_id', $actorId) ->orderBy('created_at') ->desc() // Cast because QueryBuilder::take() is typed for a string. ->take((string) $limit) ->get(); } }