Search code examples
laravellaravel-3

Get Laravel 'public' path for javascript file


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.


Solution

  • 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>
    
    ...