Okay, this is how i added media to a custom module on creation.
Note: replace <module_name> with your module name
-
Create file
<module_name>/Http/apiRoutes.php
-
Add route in apiRoutes.php something that would makes sense for your module dealing with media. Route i created was
get('<module_name>/media/file', ['as' => 'api.<module_name>.media.file', 'uses' => 'MediaController@file']);
-
Create file
<module_name>/Http/Controllers/Api/MediaController.php
add this as content MediaController.php -
Tell asgard that you added apiRoute.php in
<module_name>/Providers/RouteServiceProvider.php
in methodgetApiRoute
addreturn __DIR__ . '/../Http/apiRoutes.php';
-
Create file
<module_name>/Resources/views/admin/media/file-link.blade.php
add this as content file-link.blade.php this is basically edited file of original Media module copy (we use this only for single(have not done for multiple yet) media on creation after that we'll use Media module) . -
Include new media file in your create view (usually
<module_name>/Resources/views/admin/<entity>/create.blade.php
), place this where you want your thumbnail and browse button to appear@include('<module_name>::admin.media.file-link', ['zone' => '<zone_name>'])
you can also pass a thumbName if you want anything other than mediaThumb returned along with zone['zone' => '<zone_name>', 'thumbName' => '<my_custom_thumb_size>']
this basically will display media you choose and store its ID. -
This step has quite a bit information so i'll try my best to make some sense
Once you hit submit you will go to the
store
method of your controller (assuming you pass all validation inFormRequest
). So in thestore
method we will gathermediaId
andzoneId
passed by our view on creation and manually link media with entity since by this point we will have entityId.
So in your EntityController.php (lets say<module_name>/Http/Controllers/Admin/GameControll.php
) add relevant parts from here <entity>Controller.php, the main thing is to create your entity before and then link it with media module. I'm sure theres some parts that could be done more elegantly, but this is my development code so.
There's many <module_name>, <entity>, <entity_name> etc. so watch out
Post any questions if in case i forgot something or you didn't get me at some point.
After all of this you can follow official documentation for media module, because nothing changes onEdit and so on.