我的通知在本地工作,但是一旦部署到生产环境,它就不会在控制台中显示任何内容。
@pushonce('custom-scripts')
<script>
Echo.private('App.Models.User.' + @js($user->id)).notification((notification) => {
console.log(notification); <---nothing printed in console on production.
@this.call('addNotification', notification);
});
</script>
@endpushonce
如果我打开生产控制台并输入Echo
它看到了,所以我知道 Echo 是进口的还是其他什么。
我的应用程序部署在 Laravel Forge 上。我在产品上运行了以下命令:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan optimize:clear
似乎没有什么有任何影响。
另外,我知道 Livewire 有 Echo 监听器,但这是我能够在本地工作的唯一方法。
UPDATE
我将 Github 操作用于 CI/CD 管道,并在我的操作中运行以下脚本,我认为这已经足够了,但可能还不够:
- uses: actions/checkout@main
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Install dependencies
run: npm install
- name: Compile assets
run: npm run production
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
我想我应该发布我的构建脚本,因为我认为我并没有真正关注它们,而且我不确定它们是否设置正确。我也没有npm run build
脚本,但不知道我会在其中放入什么:
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
UPDATE:
I ran npm run prod
and npm run production
在本地,理论上应该生成与我在生产中看到的相同的包,并且我在本地得到了相同的结果,即我看到通知记录到控制台。所以它似乎与我的构建脚本无关。
此外,Echo 正在将其纳入生产版本,因为我可以从生产中的控制台调用它。所以一定还有其他原因导致它不起作用。