WildsideUK / Laravel-Userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created_by` and `updated_by` columns on your model, populated by the currently authenticated user in your application.
https://wildside.uk
MIT License
570 stars 64 forks source link

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

Open DanielKimmich opened 4 years ago

DanielKimmich commented 4 years ago

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 commented 3 years ago

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

NikunjGupta01 commented 1 year ago

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