Slider Module

  • Hi,

    I am looking for a slider module. So can you guys help me where to start. Is there any module in asgardcms?

  • Global Moderator


    There are no slider modules for asgard.

    But depending what kind of module you want you can easily make one yourself.

    Create new module as described in documentation.
    Then just use Media module for multiple files, it should be pretty straight forward.
    Add any necessary migrations for slider titles, descriptions, order and visibility.

    So all in all depending on your knowledge you can make one.

    But you can also post here full vision for the module and how it should function and i'm sure someone would make one and share with everybody.
    I even might make one later, because it's on my list for the project i'm on, but that would be closer to the time when i deal with frontend.

  • @armababy
    Thanks for reply.

    I am going to integrate Home page Slider in my latest project so am wondering. I can create new module for slider.
    But can you help me how can I use Media module in my slider module?

  • Global Moderator

    Basically you would create backend module, then you create 1 controller in that module for backend(generator will make one for each of your entities - lets say Slider).
    From there you just have to integrate media module and any other fields in your CRUD controller.

    As Media module only works with already existing data in database, for Create/Store method in your controller you would just create slider - specify any translations, texts, orders, visibility and so on.

    In your migrations don't store any information about actuall images, Media module will do that.
    After you create your Slider entry you go and integrate Media module in your Edit/Update method
    First you would specify relation as described here
    Then you would get thumbnails(they are called like that in module but you can ignore name, they just media) in your display method as described here

    After those two steps you would use already made functionality of laravel and asgrad to display images, then apply any javascript and styles in your frontend theme.

    If you have any specific question i can help you, it's very broad question now. For example what to do in controller etc.

  • @armababy


    I found on the document ( that "Next you can include the media::admin.fields.file-link partial, on the edit view only."

    But how can I include on the create view, because I want to upload slider image along with other fields like slider title,description,order,visibility.

  • Global Moderator

    @deben You cannot do that right off the bat.
    I wrote some instructions on how you can do it here but i did this for single image only.
    If you need multiple images in one slider instance you would have to customize my code.

  • @armababy

    Hey ,
    I successfully added media link to my create view. In store method I got MediaId and ZoneId. While upload file one record created on media__files table. But how can I insert data to media__imageables table and make relationship with my slider table. I have two tables slider__sliders (id,created_at,updated_at) and slider__slider_translations (id,title,description,slider_id,locale). I have no idea how to proceed next. Can you help me on this.

    How can I fetch data from the table and show on home page.

  • Global Moderator

    @deben Hey

    In my example in 7th step i described how you link them.

    This is the part that links your entity with media imageables:

                if($mediaId && $mediaZone) {
                    // Link media file with entity
                    $mediaData = [
                        'mediaId' => $mediaId,
                        '_token' => csrf_token(),
                        'entityClass' => (new \ReflectionClass($this->game))->getName(), // You can also hardcode entity here if you like
                        'entityId' => $this->game->id,
                        'zone' => $mediaZone
                    $req = Request::createFromBase(Request::create('', 'POST', $mediaData));
                    $res = $media->linkMedia($req);

    You can see last part that calls on linkMedia(). Of course you would replace $this->game with tour slider instance.

    Is this what you are asking?

  • @armababy

    Yeah, Now the data is inserting properly, but In my case I have two languages i.e English and Arabic. For each language I want to upload different image . So how can I achieve this. I mean how can I use media__file_translations ?

  • Global Moderator


    You either have to implement same stuff for multi media (basically same as single but in arrays) as i did for single media. Or you can have two single instances.
    Also you would need to store imageable_id in your slider__slider_translations so you can distinguish between media for each language.

    But i would just implement multiple-media and store imageable_id as i said. That would store several images(2 in your case) and you have correct id to retrieve it later with $slider->imageable_id that would load id for current locale.

    I'll probably work on multi upload next week so if you don't figure it out by then i'll post some examples.

  • @armababy

    It would be great if you post some examples.

  • @deben I'm not sure if you're still looking for slider module, but I had the same need, so I created one and made it available through Composer:

    It's missing docs right now, but you can just install it to your asgard same way as any other module (composer require bociancz/slider-module dev-master), then setup your slider in the backend, and then render it in your template as {!! Slider::render('slider_system_name') !!}

    Right now, it only supports generic Bootstrap carousel, but I will do customizable styling once I have little more time for this.

    If nothing else, it could point you to the right direction

Log in to reply

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