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.3] Fire BelongsToMany relation events for attach/detach/sync/toggle #14988

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,110 @@ public static function deleted($callback, $priority = 0)
static::registerModelEvent('deleted', $callback, $priority);
}

/**
* Register a relation attaching model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function attaching($relation, $callback, $priority = 0)
{
static::registerModelEvent("attaching.{$relation}", $callback, $priority);
}

/**
* Register a relation attached model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function attached($relation, $callback, $priority = 0)
{
static::registerModelEvent("attached.{$relation}", $callback, $priority);
}

/**
* Register a relation detaching model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function detaching($relation, $callback, $priority = 0)
{
static::registerModelEvent("detaching.{$relation}", $callback, $priority);
}

/**
* Register a relation detached model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function detached($relation, $callback, $priority = 0)
{
static::registerModelEvent("detached.{$relation}", $callback, $priority);
}

/**
* Register a relation syncing model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function syncing($relation, $callback, $priority = 0)
{
static::registerModelEvent("syncing.{$relation}", $callback, $priority);
}

/**
* Register a relation synced model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function synced($relation, $callback, $priority = 0)
{
static::registerModelEvent("synced.{$relation}", $callback, $priority);
}

/**
* Register a relation toggling model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function toggling($relation, $callback, $priority = 0)
{
static::registerModelEvent("toggling.{$relation}", $callback, $priority);
}

/**
* Register a relation toggled model event with the dispatcher.
*
* @param string $relation
* @param \Closure|string $callback
* @param int $priority
* @return void
*/
public static function toggled($relation, $callback, $priority = 0)
{
static::registerModelEvent("toggled.{$relation}", $callback, $priority);
}

/**
* Remove all of the event listeners for the model.
*
Expand Down
Loading