It looks like the issue you're encountering is related to the URL structure and how Livewire's assets are being served. When you have your Laravel application in a subdirectory, you need to ensure that Livewire's assets are correctly referenced.
Here are the steps to resolve this issue:
-
Update the
APP_URLin your.envfile: Make sure yourAPP_URLin the.envfile reflects the subdirectory structure. For example:APP_URL=http://my_url/dashboard -
Publish Livewire's configuration file: If you haven't already, publish the Livewire configuration file using the following command:
php artisan livewire:publish --config -
Update the Livewire configuration: Open the
config/livewire.phpfile and update theasset_urlto include your subdirectory. For example:'asset_url' => env('APP_URL') . '/livewire', -
Ensure your web server configuration is correct: Make sure your Apache configuration correctly points to the subdirectory. Your Apache configuration should look something like this:
<VirtualHost *:80> ServerName my_url DocumentRoot /var/www/html/my_app/public <Directory /var/www/html/my_app> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> -
Clear caches: Clear any cached configuration and routes to ensure your changes take effect:
php artisan config:clear php artisan route:clear php artisan view:clear -
Check your routes: Ensure that your routes are correctly set up to handle Livewire requests. You shouldn't need to manually set the script route as Livewire handles this internally.
After making these changes, your Livewire assets should be correctly referenced, and the 404 error should be resolved.
Here's a summary of the key configuration changes:
.env
APP_URL=http://my_url/dashboard
config/livewire.php
'asset_url' => env('APP_URL') . '/livewire',
Apache Configuration
<VirtualHost *:80>
ServerName my_url
DocumentRoot /var/www/html/my_app/public
<Directory /var/www/html/my_app>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
By following these steps, you should be able to resolve the issue with Livewire not being found under the subdirectory.