WildsideUK/Laravel-Userstamps

The user in the parent table is not updated when the child record is modified

Opened this issue · 2 comments

The user in the parent table is not updated when the child record is modified.
For the field "updated_at" if the date is updated

In the model the child table defines the attribute "touches".

    protected $touches = ['persons'];

    /*
    |--------------------------------------------------------------------------
    | RELATIONS
    |--------------------------------------------------------------------------
    */    
    public function persons()
    {
        return $this->belongsTo('App\Models\ContactPerson', 'contact_id', 'id');
    }

regards

I have returned to topic and found the following solution. The following code must be added in all methods: Creating, Deleting, Restoring, Uddating.

        foreach ($model->getTouchedRelations() as $relation) {
            $model->$relation->{$model->getUpdatedByColumn()} = Auth::id();
            $model->$relation->save();
        } 

I have successfully tested on Creating, Uddating.

regards

I have returned to topic and found the following solution. The following code must be added in all methods: Creating, Deleting, Restoring, Uddating.

        foreach ($model->getTouchedRelations() as $relation) {
            $model->$relation->{$model->getUpdatedByColumn()} = Auth::id();
            $model->$relation->save();
        } 

I have successfully tested on Creating, Uddating.

regards

I am new to laravel can you please guide me how and where to do this . Its urgent