Skip to content

ModelIdentifier instead of Laravel Model error in Listener depending on Listeners order for a same event. #26791

@acacha

Description

@acacha
  • Laravel Version: 5.7.16
  • PHP Version: 7.2.10-0ubuntu0.18.04.1
  • Database Driver & Version:

Description:

ModelIdentifier object is passed to Listeners instead of real Laravel Model in some cases depending on order of Listeners for same Event.

Steps To Reproduce:

git clone https://github.com/acacha/ModelIndentifierProblem
cd ModelIndentifierProblem
composer install
php artisan migrate
cp .env.example .env
php artisan key:generate

Config database in .env file and run:

php artisan migrate

Run Laravel Valet or similar and execute route /error:

http://ModelIndentifierProblem1.test/error

Error:

Undefined property: Illuminate\Contracts\Database\ModelIdentifier::$user

Will be throwed

Change listeners order in EventServiceProvider from:

IncidentStored::class => [
            LogIncidentStored::class,
            SendIncidentCreatedEmail::class,
        ],

to:

IncidentStored::class => [
            SendIncidentCreatedEmail::class,
            LogIncidentStored::class,
        ],

And problem dissapears.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions