POST http://127.0.0.1:8000/broadcasting/auth 403 (Forbidden) ,How i can resolve this error

huangapple go评论59阅读模式
英文:

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 &#39;./bootstrap&#39;;

Echo.private(&#39;App.Models.Company.&#39; + companyId)
    .notification((notification) =&gt; {
        console.log(notification);
     });

channel.php :

Broadcast::channel(&#39;App.Models.Company.{id}&#39;, function ($company, $id) {
    return (int) $company-&gt;id === (int) $id;
});

blade page :

&lt;script&gt;
   let companyId = &#39;{{ Auth::id() }}&#39;;        
&lt;/script&gt;
@vite([&#39;resources/js/app.js&#39;])

答案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(&#39;App.Models.Company.{id}&#39;, function ($company, $id) {
         return (int) $company-&gt;id === (int) $id;
 },[&#39;guards&#39;=&gt;[&#39;company&#39;]]);

huangapple
  • 本文由 发表于 2023年2月18日 17:48:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75492481.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定