Skip to content

PivotActivityFluent ​

php
class Zairakai\LaravelActivity\Support\PivotActivityFluent

Fluent API for pivot table activity logging.

Source: src/Support/PivotActivityFluent.php

Methods ​

__construct() ​

php
public function __construct(BelongsToMany $relation)

attach() ​

php
public function attach(mixed $ids, array $attributes = [], bool $touch = true): void

Attach models to the pivot table with activity logging.

by() ​

php
public function by(Model $model = null): static

Set the user or model causing this activity.

byAnonymous() ​

php
public function byAnonymous(): static

Mark activity as anonymous (no causer).

detach() ​

php
public function detach(mixed $ids = null, bool $touch = true): int

Detach models from the pivot table with activity logging.

ParameterDescription
$idsIDs to detach, or null to detach all
$touchWhether to touch parent timestamps

Returns int Number of detached records

sync() ​

php
public function sync(array|Collection|Model $ids, bool $detaching = true): array

Sync the pivot table with activity logging.

Returns array<string, array<int, int|string>>

syncWithoutDetaching() ​

php
public function syncWithoutDetaching(array|Collection|Model $ids): array

Sync without detaching with activity logging.

Returns array<string, array<int, int|string>>

toggle() ​

php
public function toggle(mixed $ids, bool $touch = true): array

Toggle models in the pivot table with activity logging.

ParameterDescription
$idsIDs to toggle
$touchWhether to touch parent timestamps

Returns array<string, array<int, int|string>> Result with 'attached' and 'detached' keys

updateExistingPivot() ​

php
public function updateExistingPivot(array|int|string $ids, array $attributes, bool $touch = true): int

Update existing pivot attributes with activity logging.

withMessage() ​

php
public function withMessage(string $message): static

Set a custom log message.

getCurrentPivotIds() ​

php
protected function getCurrentPivotIds(): array

Returns array<int, int|string>

getPivotAttributes() ​

php
protected function getPivotAttributes(array $ids): array

Returns array<int|string, array<string, mixed>>

hasChanged() ​

php
protected function hasChanged(array $before, array $after): bool

logActivity() ​

php
protected function logActivity(string $operation, mixed $before, mixed $after, string $defaultMessage): void

Write an activity log entry for the current operation.

ParameterDescription
$operationOperation name (attached, detached, synced, …)
$beforeState before the operation
$afterState after the operation
$defaultMessageFallback message when no custom message is set

normalizeIds() ​

php
protected function normalizeIds(mixed $ids): array

Returns array<int, int|string>

Documentation of 3.0.3 , built from 00cc945 on 3.0.3 by pipeline #2949084910 on 2026-10-11.