Voyager: Issue with second level of breadcrumb not using APP_URL

Created on 28 Mar 2017  路  12Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.3.30
  • Voyager Version: 0.11.7
  • PHP Version: 5.6.19
  • Database Driver & Version: MySQL 5.7.11

Description:

  • Breadcrumbs beyond the first level do not appear to be using env('APP_URL')

    breadcrum-issue

Steps To Reproduce:

  • Visit localhost/path/to/voyager/roles/create

    • Click on 'Roles' (second level) breadcrumb and the link will be wrong

Most helpful comment

I apologize for the delay, but you have to understand that this is an open source project, and none of us are getting paid to do this. We all have jobs that we do get paid for and therefore must give preference.

I do - I too run a busy open source project but try not to leave people hanging for too long without a resolution.

For your issue, you mention localhost/path/to/voyager, so I imagine you have laravel installed in such a way that it would look similar to localhost/voyager/public.

I have not even got as far as deploying to a production environment. I simply have an out of the box Laravel 5.3 install with the latest version of Voyager on my local machine. I followed the instructions on how to configure Voyager and ran into this issue straight off the bat. My setup does mean that I have a URL such as localhost/repositories/project/public/admin/voyager but I assumed Voyager would be able to handle this.

As I mentioned in my previous post, this is a very insecure setup, and we can't support it that way. If this is not the case, please let us know and we can attempt to troubleshoot it. For faster response, you're welcome to join our slack group (instructions in the readme).

What do you suggest instead? Provided routes are guarded by authentication and only necessary files are in public, I do not see how this is 'very insecure'?

One final note. You mentioned that I said "it was your configuration" and posted your voyager config file. What I meant by that statement was that it's something with how you have laravel or voyager configured, not necessarily just that one config file. Web server configuration would also apply, which is why I'm pushing best practices there.

Everything is box standard. Fresh installs of Laravel and Voyager, and WAMP with PHP 5.6.19. The only difference in my setup is Voyager isn't at localhost/voyager.


Looking at the code in navbar.blade.php the fix looks like changing $breadcrumb_url = ''; to be $breadcrumb_url = Request::root();.

Shall I submit a PR?

All 12 comments

I don't believe the breadcrumbs should be using APP_URL that way. I agree that something isn't correct since you're in a subdirectory and the links aren't representing that. I'm inclined to believe the issue might be in your configuration though. Unfortunately I don't have a recommendation on how to fix it at the moment.

  • Should each breadcrumb not be based on its parent? This clearly isn't happening.
  • Can you tell me what configuration option you believe may be causing the issue?
  • Here is my Voyager config - perhaps that will give you some insight in order to find a solution to this issue.

    • The majority of it is straight out the box.

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | User config
    |--------------------------------------------------------------------------
    |
    | Here you can specify voyager user configs
    |
    */

    'user' => [
        'add_default_role_on_register' => true,
        'default_role'                 => 'user',
        'namespace'                    => App\Models\User::class,
        'default_avatar'               => 'users/default.png',
    ],

    /*
    |--------------------------------------------------------------------------
    | Controllers config
    |--------------------------------------------------------------------------
    |
    | Here you can specify voyager controller settings
    |
    */

    'controllers' => [
        'namespace' => 'TCG\\Voyager\\Http\\Controllers',
    ],

    /*
    |--------------------------------------------------------------------------
    | Models config
    |--------------------------------------------------------------------------
    |
    | Here you can specify default model namespace when creating BREAD.
    | Must include trailing backslashes. If not defined the default application
    | namespace will be used.
    |
    */

    'models' => [
        'namespace' => 'App\\Models\\',
    ],

    /*
    |--------------------------------------------------------------------------
    | Path to the Voyager Assets
    |--------------------------------------------------------------------------
    |
    | Here you can specify the location of the voyager assets path
    |
    */

    'assets_path' => env('APP_URL', '//localhost/') . 'vendor/tcg/voyager/assets',

    /*
    |--------------------------------------------------------------------------
    | Storage Config
    |--------------------------------------------------------------------------
    |
    | Here you can specify attributes related to your application file system
    |
    */

    'storage' => [
        'disk' => 'public',
    ],

    /*
    |--------------------------------------------------------------------------
    | Database Config
    |--------------------------------------------------------------------------
    |
    | Here you can specify voyager database settings
    |
    */

    'database' => [
        'tables' => [
            'hidden' => ['migrations', 'data_rows', 'data_types', 'menu_items', 'password_resets', 'permission_role', 'permissions', 'settings'],
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Multilingual configuration
    |--------------------------------------------------------------------------
    |
    | Here you can specify if you want Voyager to ship with support for
    | multilingual and what locales are enabled.
    |
    */

    'multilingual' => [
        /*
         * Set whether or not the multilingual is supported by the BREAD input.
         */
        'bread' => false,

        /*
         * Select default language
         */
        'default' => 'en',

        /*
         * Select languages that are supported.
         */
        'locales' => [
            'en',
            //'pt',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Widgets Config
    |--------------------------------------------------------------------------
    |
    | Here you can specify voyager administration settings
    |
    */

    'widgets' => [
        [
            'name'  => 'User',
            'icon'  => 'voyager-group',
            'model' => TCG\Voyager\Models\User::class,
            'url'   => 'admin/users',
            'image' => '/images/widget-backgrounds/02.png',
        ],
        [
            'name'  => 'Post',
            'icon'  => 'voyager-news',
            'model' => TCG\Voyager\Models\Post::class,
            'url'   => 'admin/posts',
            'image' => '/images/widget-backgrounds/03.png',
        ],
        [
            'name'  => 'Page',
            'icon'  => 'voyager-file-text',
            'model' => TCG\Voyager\Models\Page::class,
            'url'   => 'admin/pages',
            'image' => '/images/widget-backgrounds/04.png',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Dashboard config
    |--------------------------------------------------------------------------
    |
    | Here you can modify some aspects of your dashboard
    |
    */

    'dashboard' => [
        // Add custom list items to navbar's dropdown
        'navbar_items' => [
            'Profile' => [
                'route'         => 'voyager.profile',
                'classes'       => 'class-full-of-rum',
                'icon_class'    => 'voyager-person',
            ],
            'Home' => [
                'route'         => '/',
                'icon_class'    => 'voyager-home',
                'target_blank'  => true,
            ],
            'Logout' => [
                'route'      => 'voyager.logout',
                'icon_class' => 'voyager-power',
            ],
        ],
        'data_tables' => [
            'responsive' => true, // Use responsive extension for jQuery dataTables that are not server-side paginated
        ],
        'widgets' => [
            'TCG\\Voyager\\Widgets\\UserDimmer',
            'TCG\\Voyager\\Widgets\\PostDimmer',
            'TCG\\Voyager\\Widgets\\PageDimmer',
        ],
    ],

    'login' => [
        'gradient_a' => '#fff',
        'gradient_b' => '#fff',
    ],

    'primary_color' => '#22a7f0',
];

+1

  • Laravel Version: 5.4
  • Voyager Version: 0.11
  • PHP Version: 5.6
  • Database Driver & Version: Postgres

I have the same issue too, the second level of breadcrumb not using correct url

Main menu with correct URL
menu_correct

Second level of breadcrumb with incorrect url
menu_incorrect

@abolinhas, it looks like your laravel installation is set up insecurely. I recommend reading up on "how to install laravel on shared hosting", as well as the laravel documentation. For example, if you leave your install as-is, you'll be able to access the .env file through the Web browser.

@fletch3555: that's been a month since I posted my configuration which you believed was the problem and you gave me no reply.

Are there no further suggestions on what the issue might be and possible solutions?

That is now 2 of us experiencing this!

@u01jmg3, I apologize for the delay, but you have to understand that this is an open source project, and none of us are getting paid to do this. We all have jobs that we do get paid for and therefore must give preference.

For your issue, you mention localhost/path/to/voyager, so I imagine you have laravel installed in such a way that it would look similar to http://localhost/voyager/public. As I mentioned in my previous post, this is a very insecure setup, and we can't support it that way. If this is not the case, please let us know and we can attempt to troubleshoot it. For faster response, you're welcome to join our slack group (instructions in the readme).

One final note. You mentioned that I said "it was your configuration" and posted your voyager config file. What I meant by that statement was that it's something with how you have laravel or voyager configured, not necessarily just that one config file. Web server configuration would also apply, which is why I'm pushing best practices there.

Hi,
I already protect my installation, thanks for the advise.
But I still getting the issue..
A quick fix is adding the missing part of path (/gips/public) in navbar.blade.php
Like this

@if($i < count(Request::segments()) & $i > 0)
                            <li class="active"><a
                                        href="/gips/public{{ $breadcrumb_url }}">{{ ucwords(str_replace('-', ' ', str_replace('_', ' ', Request::segment($i)))) }}</a>
                            </li>

I apologize for the delay, but you have to understand that this is an open source project, and none of us are getting paid to do this. We all have jobs that we do get paid for and therefore must give preference.

I do - I too run a busy open source project but try not to leave people hanging for too long without a resolution.

For your issue, you mention localhost/path/to/voyager, so I imagine you have laravel installed in such a way that it would look similar to localhost/voyager/public.

I have not even got as far as deploying to a production environment. I simply have an out of the box Laravel 5.3 install with the latest version of Voyager on my local machine. I followed the instructions on how to configure Voyager and ran into this issue straight off the bat. My setup does mean that I have a URL such as localhost/repositories/project/public/admin/voyager but I assumed Voyager would be able to handle this.

As I mentioned in my previous post, this is a very insecure setup, and we can't support it that way. If this is not the case, please let us know and we can attempt to troubleshoot it. For faster response, you're welcome to join our slack group (instructions in the readme).

What do you suggest instead? Provided routes are guarded by authentication and only necessary files are in public, I do not see how this is 'very insecure'?

One final note. You mentioned that I said "it was your configuration" and posted your voyager config file. What I meant by that statement was that it's something with how you have laravel or voyager configured, not necessarily just that one config file. Web server configuration would also apply, which is why I'm pushing best practices there.

Everything is box standard. Fresh installs of Laravel and Voyager, and WAMP with PHP 5.6.19. The only difference in my setup is Voyager isn't at localhost/voyager.


Looking at the code in navbar.blade.php the fix looks like changing $breadcrumb_url = ''; to be $breadcrumb_url = Request::root();.

Shall I submit a PR?

@u01jmg3 your solution works very well.

I think it is worth adding u01jmg3's solution. I do agree that in production you probably would not run Laravel in a sub-directory, but you may well in development (or when evaluating). And anything that makes the product look broken to anyone evaluating it needs to be addressed.

Might be worth affecting a similar update in the home link in the user drop-down.

This has been fixed in 700e021

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings