Jan 22, 2025
0
Level 6
Activity Log subject_id is 0
I'm using this plugin to log activity
https://filamentphp.com/plugins/rmsramos-activitylog
This is my implementation
on my UserResource
Forms\Components\Group::make([
Forms\Components\DatePicker::make('birthdate')
->label('Birthdate'),
Forms\Components\Select::make('gender')
->label('Gender')
->options(Gender::array())
->placeholder('Select Gender')
])
->relationship('detail')
->columns(),
and in the User model
public function detail(): HasOne
{
return $this->hasOne(UserDetail::class, 'id');
}
and in the UsersDetail model
public function tapActivity(Activity $activity, string $eventName)
{
dd($activity);
$activity->properties = $activity->properties->merge([
'ip' => request()->ip(),
'user_agent' => request()->userAgent(),
]);
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logAll()
->logOnlyDirty()
->setDescriptionForEvent(fn(string $eventName) => "This model has been {$eventName}")
->useLogName(class_basename($this));
}
Though it will store the log but the problem is the subject_id is 0 and the id in the properties->attributes is 0
the case is the user details is associate in User
as of now if if dd the activity in the UserDetails model I have this
#attributes: array:8 [▼
"log_name" => "UserDetail"
"properties" => "
{"attributes":{"birthdate":"1888-07-01T00:00:00.000000Z","gender":"male","id":0,"updated_at":"2025-01-22T06:16:07.000000Z","created_at":"2025-01-22T06:16:07.000
▶
"
"causer_id" => 1
"causer_type" => "App\Models\User"
"batch_uuid" => null
"event" => "created"
"subject_id" => 0
"subject_type" => "App\Models\UserDetail"
]
The output should be like this, If I created new user and the id store id is 233 then the subject_id and id in the attributes should be 2333
#attributes: array:8 [▼
"log_name" => "UserDetail"
"properties" => "
{"attributes":{"birthdate":"1888-07-01T00:00:00.000000Z","gender":"male","id":233,"updated_at":"2025-01-22T06:16:07.000000Z","created_at":"2025-01-22T06:16:07.000
▶
"
"causer_id" => 1
"causer_type" => "App\Models\User"
"batch_uuid" => null
"event" => "created"
"subject_id" => 233
"subject_type" => "App\Models\UserDetail"
]
Please or to participate in this conversation.