How to create a new Post with a Thumbnail
I see that I can add a thumbnail when I update a post, but not when I create a new one. Can I do that or should I modify the Blog Module?
There's currently no way out of the box.
I did thumbnails on creation for my module, you would probably need to extend blog classes to do that without messing up your future updates.
If you need some info on how i can share with my implementation for custom module.
Yes please, if you can I would like to see it. Thanks a lot!
Okay, this is how i added media to a custom module on creation.
Note: replace <module_name> with your module name :8ball:
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']);
<module_name>/Http/Controllers/Api/MediaController.phpadd this as content MediaController.php
Tell asgard that you added apiRoute.php in
return __DIR__ . '/../Http/apiRoutes.php';
<module_name>/Resources/views/admin/media/file-link.blade.phpadd 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 :dancer: Once you hit submit you will go to the
storemethod of your controller (assuming you pass all validation in
FormRequest). So in the
storemethod we will gather
zoneIdpassed 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.
Sorry to resurrect this topic, but it worked perfectly for my super custom treatment of uploads in special modules, which even supports different media upload for each locale/language :)