How to show the user that update a record

Hi guys!! I need some help,

I have a column that show the date in which an user update a record.
It’s all ok. Now, I need to show, near the date, the name of the user that have update the record.
For example: 2020-06-12 10:05:36 from Michael

I have to change the value of the attribute? The implementation is this:

[
‘attribute’ => 'last_modify,
‘value’ => function ( $model ) {
return $model->last_modify;
},
‘label’ => ‘Last modify’
],

What I have to add at this code?
Thank you very much!!!

Hi, you just need to add an attribute which stores username who updated your record. For example if you have database column/model attribute which stores editor’s username named updated_by, change the returned value as shown below.

[
'attribute' => 'last_modify',
'value' => function ( $model ) {
return $model->last_modify . ' from ' . $model->updated_by;
},
'label' => 'Last modify'
],

thank you. I found another way that I show here for others or interested:

[
‘attribute’ => ‘last_modify’,
‘value’ => function ( $model ) {
$variable = Yii::$app->user->identity->username;
return $model->last_modify." from ".$variable;
},
‘label’ => ‘Last modify’],
],

That is simply getting the current user’s name. It is in no way tied to the record and/or who actually performed the last update.

As kubove indicated, you need to add a new attribute to your table and store the userid value when changes are made. You could code it in your controller action or perhaps use a beforeSave() function within your model to automatically populate it.