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

jlrdw's avatar
Level 75

Laravel 10 asset helper [Solved]

In ver 9 I can use asset helper without the asset_url config like:

<link href="<?php echo asset('assets/css/dog/style.css'); ?>" rel="stylesheet">

But in version 10 it's not getting the correct url without adding:

'asset_url' => 'http://localhost/laravel10/',

To config.

So ver 9 auto adds http://localhost/laravel913/ which you can see in view source.

Ver 10 using asset helper only gets relative path.

I looked all over for any changes to asset helper, but couldn't find any. Any ideas why the difference?

0 likes
9 replies
jlrdw's avatar
Level 75

@vincent15000 yes I know why there is an asset_url. But I've never had to use it in any prior version, the asset helper always worked without it. It was late so I haven't dug into framework code yet, when I get a chance I will do it today.

Right now I'm just experimenting with version 10.

1 like
vincent15000's avatar

@jlrdw I didn't say that you don't know that there is an asset_url ;). I just wanted to say that perhaps it's now necessary to always define this property just to let anybody customize the asset URL.

1 like
vincent15000's avatar
Level 63

@jlrdw Yes exactly, I also compared both versions.

Perhaps it's an issue that will be rectified.

1 like
jlrdw's avatar
Level 75

@vincent15000 I found the culprit:

Version 9 in config\app.php

'asset_url' => env('ASSET_URL'),

Version 10

'asset_url' => env('ASSET_URL', '/'),

Basically instead of:

<link href="http://localhost/laravel10/assets/css/dog/style.css" rel="stylesheet">

you get:

<link href="/assets/css/dog/style.css" rel="stylesheet">

if clicked on

http://localhost/assets/css/dog/style.css

The laravel10 part is missing.

I just took out the stray slash:

'asset_url' => env('ASSET_URL'),

I just missed seeing this at first.

Also: https://github.com/laravel/framework/issues/46092

2 likes
Sinnbeck's avatar

@jlrdw so you are running laravel in a sub folder? Curious how you configured that

1 like
jlrdw's avatar
Level 75

@Sinnbeck main laravel out of web, see http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/ Very secure this way.

Basically what was public is now subfolder, nothing else in in there. And really, main laravel like app, vendor, everything else can go anywhere in the file system, just not in web folders.

You can actually do the same with nginx.

Edit:

Assets do go there, but images are above (out of) web served via a image controller and a route. I have never messed with a symbolic link except certain setups where required in Linux.

I got used of this because it's the way I served images when years ago I deployed to a tomee server. Images wasn't part of the war file.

1 like

Please or to participate in this conversation.