Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wesleyderoode's avatar

Prefixed route group also adds prefix to assets

I am using a route group with a prefix as shown below:

Route::group(['prefix' => 'auth'], function () {
        // Login routes...
        Route::get('login', 'Auth\LoginController@showLoginForm')->name('get.auth.login');
        Route::post('login', 'Auth\LoginController@login')->name('post.auth.login');
        Route::post('logout', 'Auth\LoginController@logout')->name('post.auth.logout');

        // Registration routes...
        Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('get.auth.register');
        Route::post('register', 'Auth\RegisterController@register')->name('post.auth.register');

    });

My assets on these pages wil not load because their urls get prefixed. <img src="{{ asset('assets/images/logo.svg') }}" class="logo" alt=""> returns: http://mywebsite.dev/auth/assets/images/logo.svg instead of: http://mywebsite.dev/assets/images/logo.svg

How can i fix this?

0 likes
7 replies
tykus's avatar

Don't use the asset() helper method - it gets the url from the app instance.

willvincent's avatar
Level 54

Yeah, seems like there's no compelling reason to not simply do:

<img src="/assets/images/logo.svg" class="logo" alt="">
1 like
bobbybouwmann's avatar

Make sure you add a slash (/) in front of the styles so it looks at the public directory of your app

1 like
wesleyderoode's avatar

Well that's weird, if i use:

<img src="/assets/images/logo.svg" class="logo" alt="">

It still doesn't work. Although it shows as: assets/images/logo.svg in the page source, the link itself when clicked points to auth/assets/images/logo.svg.

willvincent's avatar

Maybe you should show us your blade template...

1 like
wesleyderoode's avatar

This:

<img src="assets/images/logo.svg" class="logo" alt="">

Should be:

<img src="/assets/images/logo.svg" class="logo" alt="">

This is embarrassing, i forgot to start the path with a /. I thougt i did after reading @bobbybouwmann answer but i changed it for the mobile version of my logo that shows on smaller screens and not for the desktop version. Thanks for the help!

Please or to participate in this conversation.