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

octal's avatar
Level 1

How does Laravel/Blade handle assets ?

Hello, I'm having a problem with my assets (images and js files).

I have created a global_asset folder inside my public folder.

I have created a resource controller ProjectController to route user either to the list of projects (index.blade.php) or to view a single project (show.blade.php)

Both index.blade.php and show.blade.php extends the same initial layout (my template.blade.php).

The PROBLEM:

in the template.blade.php I have included some assets like this:

<script src="global_assets/js/plugins/visualization/d3/d3.min.js"></script>

When the controller routes me to the index ( /domain/projects) (to show all projects), this works and all assets are accessed correctly.

When the controller routes me to the create.blade.php file to show only a single project ( /domain/projects/{idOfProject} ) this doesn't work, in telescope it shows that the assest are accessed as if they were in "/projects/global_assets/...."

0 likes
4 replies
siangboon's avatar

try add "/" in front of the global_assets and see..

<script src="/global_assets/js/plugins/visualization/d3/d3.min.js"></script>
1 like
Nash's avatar

The path you have specified is relative to your current URL. This is not specific to Laravel but to how HTML works. If you put a slash (/) before your path, it will always refer to the root. You could also just add the full URL or use Larvel's asset helper: src="{{ asset('global_assets/js/plugins/visualization/d3/d3.min.js') }}"

octal's avatar
Level 1

@NASH - My problem is not with how HTML works or expect the references to css/js/img to be provided. My problem is how can I force those links to be independent of the relative path of my views blade files.

Well, I had to use the asset(..) helper function and even of the assets are in a global directory at the root of my website (in public folder in laravel) I had to define the ASSET_URL= in the .ENV file (in my case it's simply a blank).

Now everything works as expected.

Please or to participate in this conversation.