Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DanielKimmich opened this issue Jul 16, 2020 · 2 comments

Comments

@DanielKimmich
Copy link

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
Copy link
Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants