mardi 3 novembre 2015

Inject different model in Laravel 5.1 observers

I have two models

Item / ItemTranslation (one to many relation).

I am using a model observer for ItemTranslation and it works fine.

public function created(ItemTranslation $itemTranslation)
{
}

I was wondering if it is possible to inject the Item model instead of the model itself.

public function created(Item $item)
{
}

It expects to recive an ItemTranslation instance.

[ErrorException] Argument 1 passed to App\Observers\ItemTranslationObserver::created() must be an instance of App\Observers\Item, instance of App\ItemTranslation given.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire