Skip to content

About

Example for the issue: Laravel 5.8 and syncing event: Call to undefined method exception #28050

Resources

Stars

5 stars

Watchers

1 watching

Forks

Repository files navigation

Laravel 5.8 syncing / attaching / detaching events

Example for the issue: Laravel 5.8 and syncing event: Call to undefined method exception #28050

The release notes were misleading and they have been changed laravel/docs#5096.

For more info laravel/framework#28050

Installation

  • git clone https://github.com/danielefavi/laravel-issue-example.git
  • composer install
  • set your .env file
  • php artisan migrate
  • php artisan key:generate

Detailed explanation

On Laravel 5.8, when you are using the methods sync, attach or detach is going to be fired the appropriate model events (creating, updating, saving, ...) for the called action. Note that using sync, attach or detach is not going to fire any event like syncing, attaching or detaching.

More specifically, the sequence of events fired for each element passed to the sync method are:

  • saving
  • creating
  • created
  • saved

The sequence of events fired for each element passed to the attach method are:

  • saving
  • creating
  • created
  • saved

The sequence of events fired for each element passed to the detach method are:

  • deleting
  • deleted

So if you want to observe the syncing operation you actually have to observe the saving (or saved) event from the pivot model (in this case ProjectUser):

class ProjectUser extends Pivot
{
    public static function boot()
    {
        parent::boot();

        static::saving(function ($item)  {
			// this will die and dump on the first element passed to ->sync()
            dd($item);
        });
    }
}

About

Example for the issue: Laravel 5.8 and syncing event: Call to undefined method exception #28050

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages