Laravel-Userstamps icon indicating copy to clipboard operation
Laravel-Userstamps copied to clipboard

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

Open DanielKimmich opened this issue 4 years ago • 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

DanielKimmich avatar Jul 16 '20 22:07 DanielKimmich

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

DanielKimmich avatar Mar 18 '21 15:03 DanielKimmich

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

NikunjGupta01 avatar Sep 12 '23 03:09 NikunjGupta01