You can use the media uploaded in any module you make.
Lets say you have an articles module, and want your article to have a cover image. This is when you'll want a 'one-to-one' relation type. If for instance you have a product, which can have multiple images (a gallery), you'll want a 'one-to-many' relation type.
In this example, cover_image and gallery are what we call "zones". Zones are basically groups of files, which allows us to get all (or one) file(s) for a specific group, for an entity.
Zones can be imagined as part of website pages, to which we assign files.
It is important to note that both types use the same morphToMany relation behind the scenes. It's only the UI which changes.
These events will let the media module know it needs to handle the data from the form to link / unlink files.
You will need to trigger an event in your repository, when the entity was created and when it was updated. Both events will need the following:
Implement the Modules\Media\Contracts\StoringMedia interface
Needs to have 1) the Entity and 2) the data from the form
The interface requires 2 methods, to return each of those properties
This is an example of one of those events:
class RecipeWasCreated implements StoringMedia
public function __construct($recipe, $data)
$this->recipe = $recipe;
$this->data = $data;
* Return the entity
* @return \Illuminate\Database\Eloquent\Model
public function getEntity()
* Return the ALL data sent
* @return array
public function getSubmissionData()