How can we add a add extra column in activity log table ( spatie-activitylog )

69 Views Asked by At

I need another field in the activity log table document_Id. Is this possible?

ActivityLog Model File code

class ActivityLog extends Model
{

    public $table = 'activity_log';

    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';

    protected $primaryKey = 'id';

    public $fillable = [
        'log_name',
        'description',
        'subject_type',
        'subject_id',
        'document_id',
        'causer_type',
        'causer_id',
        'properties'
    ];
}

Controller File Code.

class ReportHeader extends ChangeConnection
{
    public $table = 'reportheader';

    const CREATED_AT = 'createdDateTime';
    const UPDATED_AT = 'timestamp';

    protected $primaryKey = 'reportSystemID';
    protected static $logAttributes = [ .. ];
    protected static $logName = 'reportheader';

    use LogsActivity;

    public $fillable = [ .. ];

}

I need another field in the activity log table document_Id. I am using activity log. I want to add extra column, document_Id to the activity log table.

1

There are 1 best solutions below

1
On

It is possible to add a new field.

  • create a new column in your database called "activity log" with the name "document id" and the proper data type.
  • Also, you must add the "document id" property to the ActivityLog Model's $fillable array.
  • To ensure that the value of "document id" is logged when an activity is recorded, you must also edit the LogsActivity trait in the ReportHeader class to include "document id" in the $logAttributes property.
  • You must then pass the value of "document id" as an attribute when creating the activity log in the code where you are creating it.
  • Finally, you need to update the database with a new column,   In Laravel, you can do this using migrations.