英文:
POST http://127.0.0.1:8000/broadcasting/auth 403 (Forbidden) ,How i can resolve this error
问题
app.js:
import './bootstrap';
Echo.private('App.Models.Company.' + 公司ID)
.notification((通知) => {
console.log(通知);
});
channel.php:
Broadcast::channel('App.Models.Company.{id}', function ($公司, $id) {
return (int) $公司->id === (int) $id;
});
blade 页面:
<script>
let 公司ID = '{{ Auth::id() }}';
</script>
@vite(['resources/js/app.js'])
英文:
app.js :
import './bootstrap';
Echo.private('App.Models.Company.' + companyId)
.notification((notification) => {
console.log(notification);
});
channel.php :
Broadcast::channel('App.Models.Company.{id}', function ($company, $id) {
return (int) $company->id === (int) $id;
});
blade page :
<script>
let companyId = '{{ Auth::id() }}';
</script>
@vite(['resources/js/app.js'])
答案1
得分: 0
这个问题已经解决了,因为我在我的系统中使用了守卫,它不会识别除了默认守卫之外的任何守卫。我在通道路由中定义了守卫,如下:
Broadcast::channel('App.Models.Company.{id}', function ($company, $id) {
return (int) $company->id === (int) $id;
}, ['guards'=>['company']]);
英文:
This problem has been solved, because I am using guards in my system, it does not recognize any guards other than the default guard
I defined the guard in the channel route such as :
Broadcast::channel('App.Models.Company.{id}', function ($company, $id) {
return (int) $company->id === (int) $id;
},['guards'=>['company']]);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论