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

[5.8] Replicating model event #28077

Merged
merged 1 commit into from
Apr 4, 2019
Merged

[5.8] Replicating model event #28077

merged 1 commit into from
Apr 4, 2019

Conversation

jerguslejko
Copy link
Contributor

This PR introduces "replicating" model event which is fired when $model->replicate() is called.

This is useful when "replication" is a part of the domain logic. My usecase: I need to reset an attribute every time a model is replicated, because that attribute is specific to the model.

@taylorotwell
Copy link
Member

How many different models do you have this use case for? Is it mainly a single model?

@AbdelElrafa
Copy link
Contributor

@jerguslejko Why not have a replicating and a replicated event?

@devcircus
Copy link
Contributor

Maybe do the replication in a method on your model and fire a custom event. IMO it doesn't seem like a common enough use-case for core.

@taylorotwell
Copy link
Member

Maybe do the replication in a method on your model and fire a custom event. IMO it doesn't seem like a common enough use-case for core.

This is kinda what I was getting at with my comment. If you're just doing this on a particular model it may be easier to just make it a method in your application.

@jerguslejko
Copy link
Contributor Author

@AbdelElrafa replicating a model does not create a new database record. therefore replicated would be the same as replicating

@taylorotwell I need to be able to dynamically register replication logic in a service provider. using the replicating model event makes it super easy

@AbdelElrafa
Copy link
Contributor

AbdelElrafa commented Apr 2, 2019

@jerguslejko I was thinking, like during the replicating event you can make some api call to do something, and during the replicated event you can just save the model automatically. Give the user the choice like we do with the other events.

Take a look at this, https://laravel.com/docs/5.0/eloquent#model-events.
Like during the replicating event you can stop it by returning false.

@taylorotwell taylorotwell merged commit 7d24f91 into laravel:5.8 Apr 4, 2019
@jerguslejko jerguslejko deleted the replicating-event branch April 4, 2019 13:31
@ShekhSaifuddin007

This comment has been minimized.

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

Successfully merging this pull request may close these issues.

5 participants