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

Conversation

Projects
None yet
5 participants
@jerguslejko
Copy link
Contributor

commented Mar 31, 2019

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

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

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

@AbdelElrafa

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

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

@devcircus

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

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

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

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

This comment has been minimized.

Copy link
Contributor Author

commented Apr 2, 2019

@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

This comment has been minimized.

Copy link
Contributor

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@jerguslejko jerguslejko deleted the jerguslejko:replicating-event branch Apr 4, 2019

@ShekhSaifuddin007

This comment has been minimized.

Copy link

commented Apr 5, 2019

@taylorotwell Laravel 5.8 has routing problem, when it's on live server. Local server it's okay...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.