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

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

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

问题

app.js:

  1. import './bootstrap';
  2. Echo.private('App.Models.Company.' + 公司ID)
  3. .notification((通知) => {
  4. console.log(通知);
  5. });

channel.php:

  1. Broadcast::channel('App.Models.Company.{id}', function ($公司, $id) {
  2. return (int) $公司->id === (int) $id;
  3. });

blade 页面:

  1. <script>
  2. let 公司ID = '{{ Auth::id() }}';
  3. </script>
  4. @vite(['resources/js/app.js'])
英文:

app.js :

  1. import &#39;./bootstrap&#39;;
  2. Echo.private(&#39;App.Models.Company.&#39; + companyId)
  3. .notification((notification) =&gt; {
  4. console.log(notification);
  5. });

channel.php :

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

blade page :

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

答案1

得分: 0

这个问题已经解决了,因为我在我的系统中使用了守卫,它不会识别除了默认守卫之外的任何守卫。我在通道路由中定义了守卫,如下:

  1. Broadcast::channel('App.Models.Company.{id}', function ($company, $id) {
  2. return (int) $company->id === (int) $id;
  3. }, ['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 :

  1. Broadcast::channel(&#39;App.Models.Company.{id}&#39;, function ($company, $id) {
  2. return (int) $company-&gt;id === (int) $id;
  3. },[&#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:

确定