Alternative Dashboard / Custom views in dashboard

  • I'd like to know if is possible to publish the Dashboard's module assets, as my project doesn't need the widget funcionality, but a pretty straightforward home page instead. Doing this via widgets would be overkill, as I want to keep things simple.

    Is there any way to rewrite the Dashboard views? I tried:
    php artisan vendor:publish --provider="Modules\Dashboard\Providers\DashboardServiceProvider"

    But I get in response the following message:
    Nothing to publish for tag [].

    Is there something I'm missing?

  • Global Moderator


    A bit lost here, so you want to publish dashboard assets and rewrite views?

    For publishing everything in Assets folder of module: php artisan module:publish Dashboard

    I can see that Dashboard module are not exposing views.
    You would need to edit DashboardServiceProvider

        public function boot()
                __DIR__ . '/../Resources/views' => base_path('resources/views/asgard/dashboard'),
            ], 'views');
            $this->loadViewsFrom(base_path('Themes/'.config('asgard.core.core.admin-theme').'/views/modules/dashboard'), 'dashboard');
            $this->loadViewsFrom(base_path('resources/views/asgard/dashboard'), 'dashboard');
            $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'dashboard');

    php artisan vendor:publish --provider="Modules\Dashboard\Providers\DashboardServiceProvider" --tag="views"

    Thats a PR for dashboard module for sure.

    Update: PR filled

  • @armababy

    My idea was to modify just the dashboard views, as widgets are a feature not planned for the project I'm working on, (In fact, I just need a kind of welcome page instead of a dashboard).

    Adding that function to DashboardServiceProvider worked like a charm. I guess that for other modules I have to follow same pattern?

    Also, should I remove Dashboard module from .gitignore?

    Btw, many thanks for your contribution and by making a PR!

  • Global Moderator


    Yeah same thing for all modules that you want view modified where view composers are not enough.
    Probably we/i should do a PR's for all asgard modules that has views to expose them and also include Theme override line.

    Personally i ignore everything in Modules folder and for my custom modules i just pull them from my private repositories.
    For any core module edits i do i try to PR that changes if it makes sense in global manner. If PR makes no sense for project sake i keep separate list of modified files and code so i can re-apply fixes on fresh installs.

    Probably good strategy would be replace modified module with core one and use again custom repository until thing you need is in the core module.

    For dashboard module PR is merged and in the master, but you would modify composer.json to pull master until tagged release comes over.
    If you do not want to pull master you could remove Dashboard from .gitignore and just remember that you made change so you don't accidentally update it with original one.

  • @armababy

    Fantastic, many thanks for your tips about maintaining these modifications.

    I got another question:

    Although I've successfully published the views and made my own version, the Dashboard is still using the 'vanilla' version (the view into the Resources folder of the Dashboard module). The only way to make visible the published views is to delete (or rename) the view I'm referring to. But certainly that is not the way to go.

    I'm missing something? Why the modified [published] view is not showing?

  • Global Moderator


    I debugged this problem and it's because CoreServiceProvider registers Modules/<module>/Resources/views before any module can do local views location declarations and is placed on 0th index and thus always finds those views first.

    This applies to all modules of asgard and any custom modules except users module since this is skipped for that one.

    For now you have two options.

    First is to edit CoreServiceProvider:

         * Register the view namespaces for the modules
         * @param Module $module
        protected function registerViewNamespace(Module $module)
            if ($module->getName() == 'user' || $module->getName() == 'dashboard') {
                $module->getPath() . '/Resources/views'

    Second one i like better, in DashboardServiceProvider:

    // instead of 
    $this->loadViewsFrom(base_path('Themes/'.config('asgard.core.core.admin-theme').'/views/modules/dashboard'), 'dashboard');
    // do this
    $this->app['view']->prependNamespace('dashboard', base_path('Themes/'.config('asgard.core.core.admin-theme').'/views/modules/dashboard'));

    That would place every prepend to 0th position. And we can control then what folders to look first.

    I'll keep this one in mind and look if any good PR can be done.

    This is how final version should look like for boot:

        // use use Modules\Workshop\Manager\StylistThemeManager;
        public function boot(StylistThemeManager $theme)
                __DIR__ . '/../Resources/views' => base_path('resources/views/asgard/dashboard'),
            ], 'views');
            $this->app['view']->prependNamespace('dashboard', base_path('resources/views/asgard/dashboard'));
            $this->app['view']->prependNamespace('dashboard', $theme->find(config('asgard.core.core.admin-theme'))->getPath() . '/views/modules/dashboard');

    Will have to re-PR upon new development of situation.

  • @armababy

    Great, thanks!

    But I'm not able to understand at all these two lines:

    $this->app['view']->prependNamespace('dashboard', base_path('resources/views/asgard/dashboard'));
    $this->app['view']->prependNamespace('dashboard', $theme->find(config('asgard.core.core.admin-theme'))->getPath() . '/views/modules/dashboard');

    I get that those lines 'load' the views and make it available for the module, but why works in that order? I understand the last view loaded overrides the first one loaded?

    Anyway, it does work! (But at this moment it's a bit... magical for me).

  • Global Moderator


    Yeah it basically takes namespace and path and adds that path for that namespace and places it in first position (0th index).

    With this code what would happen is:

    1. CoreServiceProvider registers Modules/{module}/Resources/views as first hint.
    2. Then boot method prepends to hints array resources/views/asgard/dashboard
    3. And finally we prepend to hints array {theme_path)/views/modules/dashboard'

    So in the end we will get hints array like (order of folders that Laravel checking for views):

        0 => '/var/myserverpath/asgard/Themes/{mytheme}/views/modules/dashboard',
        1 => '/var/myserverpath/asgard/resources/views/asgard/dashboard',
        2 => '/var/myserverpath/asgard/Modules/Dashboard/Resources/views'

    Previously it was always having '/var/myserverpath/asgard/Modules/Dashboard/Resources/views' as 0th index.
    Since loadViewFrom appends to hints array.

    if you dd($this->app['view']) you can see in Filesystem object array of hints.

    Update: did PR for Revert of previous PR :8ball:
    And new PR to address all the findings we did here

  • @armababy

    Ah, allright! So views are prepended... that's what I was missing!

    Thanks @armababy for taking your time to explain it and being so helpful!

  • Global Moderator

    Np, i usually find me learning of new stuff exactly when i try to solve problem for someone else or myself.

Log in to reply

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