Search code examples
laravel-livewire

Laravel livewire script full path


If i have a laravel project in

c:\xampp\htdoc\proj -> http://localhost/proj

and public url

c:\xampp\htdoc\projpubl -> http://localhost/projpubl

Using the laravel livewire, the javascript url is

<script src="/livewire/livewire.js?id=83b555bb..." data-turbo-eval="false" data-turbolinks-eval="false"></script>

I want to do the url like:

<script src="http://localhost/projpubl/livewire/livewire.js?id=83..

How to do?


Solution

  • If you host your application in a path which is not the root in your domain, you need to publish the Livewire configuration and set the asset_base_url property. This is stated in the documentation.

    To publish the config-file, run

    php artisan livewire:publish --config
    

    You will get a copy of the Livewire-config file in your project, located at config/livewire.php.

    Find the asset_url property (aprox. line 57) and set it to

    'asset_url' => '/projpubl'
    

    Just to note, since I don't know how you've set your project up, anything outside the public directory in Laravel should never be accessible from any HTTP request.