-
Notifications
You must be signed in to change notification settings - Fork 109
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
Where to dispatch jobs/send events #11
Comments
Hi Josh. Your totally right, this would be best on the controller rather than a model listener. In the current version you'd need to overload the commit method: For example: protected function commit(Model $model)
{
$isUpdate = $model->exists;
$result = parent::commit($model):
if ($result && $isUpdate) {
dispatch(new SomeEvent($model));
}
return $result;
} That'll work with the current version ( A slightly better solution might be for me to put in protected methods - protected function didUpdate(Model $model)
{
dispatch(new SomeEvent($model));
} |
Yeah, that seems like a good solution to me. I guess there could also be a Maybe the naming convention could be similar to Eloquent? protected function updating(Model $model) { // ... }
protected function updated(Model $model) { // ... } What do you think? I don't mind helping out with a PR for this. |
I like the idea of using the Eloquent names - I'd normally use I'm happy for you to submit a PR if you have time. You need to submit against the |
Oh, if you are doing a PR you don't need to worry about tests. I haven't got this package unit tested at the moment as it's fully integration tested in two production apps. So I'd check that your PR doesn't break those apps before merging. (I am planning on adding unit tests in the future but at the moment I've got close to 100% test coverage with the integration tests, so to save development time I'm relying on those.) |
Ok, no problem. I should be able to take a look at it this evening. |
Adds callbacks for creating/created/updating/updated models on a controller. Callbacks can be defined in controllers that inherit the `EloquentController`. ``php class UsersController extends EloquentController { protected function creating(Model $model) { // Before the model is created. } protected function created(Model $model) { // After the model has been created. } protected function updating(Model $model) { // Before the model is updated. } protected function updated() { // After the model has been created. } } `` --- See cloudcreativity#11 for a bit more discussion.`
Adds callbacks for creating/created/updating/updated models on a controller. Callbacks can be defined in controllers that inherit the `EloquentController`. ```php class UsersController extends EloquentController { protected function creating(Model $model) { // Before the model is created. } protected function created(Model $model) { // After the model has been created. } protected function updating(Model $model) { // Before the model is updated. } protected function updated() { // After the model has been created. } } ``` --- See cloudcreativity#11 for a bit more discussion.`
@josh-taylor thanks for your input! This has been included in the |
My normal approach for dispatching jobs/sending events would be in the controller action, for example here where we would send an email that a model has been updated:
What would be the recommended approach when extending from the
EloquentController
to achieve something similar?My initial thoughts would be to:
update()
method on the controllerupdated
eventThe text was updated successfully, but these errors were encountered: