Laravel-medialibrary: How to get the Parent Model from the media

Created on 7 Aug 2017  路  2Comments  路  Source: spatie/laravel-medialibrary

I am consuming the events as discussed in https://docs.spatie.be/laravel-medialibrary/v5/advanced-usage/consuming-events, but what I am trying to achieve is to get the associated parent model that was used to attach this media. Is there an easier way to do this.

Currently, I am doing this on the Event definition.

$model = $event->media->getModel();
$modelInstance = app($model->model_type);
$libraryItemInstance = $libraryItemModel->find($model->model_id);

Most helpful comment

Here's an easy way to get the model where the media is attached to:

$model = $media->model;

All 2 comments

Here's an easy way to get the model where the media is attached to:

$model = $media->model;

馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brendt picture brendt  路  4Comments

Krato picture Krato  路  4Comments

stayallive picture stayallive  路  4Comments

netanelwebninja picture netanelwebninja  路  3Comments

Nks picture Nks  路  3Comments