Get Laravel 'public' path for javascript file
Asked Answered
B

1

9

I'm unsure how I can get something equivalent to: path('public') to work in a Javascript file?

I basically just need the path to the public folder for displaying some images from my JS file.

Bopp answered 14/5, 2013 at 9:43 Comment(1)
I always just do /public and it works. I'm not sure if there's a more modular way to do it. Sorry that I'm not more help.Satinet
P
11

You could opt to create a variable in JavaScripts global namespace in the head of your document and use PHP to echo out the public path.

<head>
    <script>
        var public_path = '{{ path('public') }}';
    </script>

...
Pike answered 14/5, 2013 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.