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?


  • Global Moderator

    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!

  • Global Moderator

    Okay, this is how i added media to a custom module on creation.

    Note: replace <module_name> with your module name :8ball:

    1. Create file <module_name>/Http/apiRoutes.php

    2. 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']);

    3. Create file <module_name>/Http/Controllers/Api/MediaController.php add this as content MediaController.php

    4. Tell asgard that you added apiRoute.php in <module_name>/Providers/RouteServiceProvider.php in method getApiRoute add return __DIR__ . '/../Http/apiRoutes.php';

    5. 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) .

    6. 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>', ['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.

    7. 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 store method of your controller (assuming you pass all validation in FormRequest). So in the store method we will gather mediaId and zoneId 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.

  • 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 :)

  • admin

    That's awesome!

Log in to reply

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.