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

Before & After commit hooks #12

Merged

Conversation

josh-taylor
Copy link
Contributor

Adds callbacks for creating/created/updating/updated models on a controller.

Callbacks can be defined in controllers that inherit the EloquentController.

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 #11 for a bit more discussion.`


$result = $model->save();

$this->afterCommit($model, $isUpdating);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think afterCommit should only be called if $result is true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

@lindyhopchris
Copy link
Member

@josh-taylor thanks for taking the time to submit! Just a few comments above but this should be good to merge once you've taken a look at those.

I'll probably add saving, saved, deleting and deleted hooks as well, but I can do those later once this is merged.

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 josh-taylor force-pushed the before-after-commit-hooks branch from 5e11231 to 8911c53 Compare July 27, 2016 08:17
@josh-taylor
Copy link
Contributor Author

Updated!

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.

2 participants