Php 推送器:没有对私人用户的回调。6对于推送器:订阅\u错误
我在使用Pusher和Laravel时有点问题。我已将channels.php文件配置为在此频道上广播(仅针对经过身份验证的用户)—— 我的.env文件显示-Php 推送器:没有对私人用户的回调。6对于推送器:订阅\u错误,php,laravel,npm,pusher,laravel-echo,Php,Laravel,Npm,Pusher,Laravel Echo,我在使用Pusher和Laravel时有点问题。我已将channels.php文件配置为在此频道上广播(仅针对经过身份验证的用户)—— 我的.env文件显示- BROADCAST_DRIVER=pusher PUSHER_APP_ID="652357" PUSHER_APP_KEY="13e1**********55" PUSHER_APP_SECRET="1e******667f8*****9f" PUSHER_APP_CLUSTER=eu 我的broadcasting.php中有这个 '
BROADCAST_DRIVER=pusher
PUSHER_APP_ID="652357"
PUSHER_APP_KEY="13e1**********55"
PUSHER_APP_SECRET="1e******667f8*****9f"
PUSHER_APP_CLUSTER=eu
我的broadcasting.php中有这个
'default' => env('BROADCAST_DRIVER', 'log'),
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER', 'eu'),
'encrypted' => true,
],
],
该事件在my UsersController.php中激发
<?php
namespace App\Http\Controllers;
use App\Events\UserStatusEvent;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['auth', 'profile'])->except('show', 'help');
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param string $user
* @return \Illuminate\Http\Response
*/
public function update(Request $request, User $user)
{
$data = $request->only(['first_name', 'last_name', 'middle_name', 'email', 'city', 'dob', 'gender', 'address']);
$user->update($data);
event(new UserStatusEvent(auth()->user()));
// if ($request->ajax()) {
// return response()->json([
// 'status' => 'Profile Update successful.',
// 'errors' => app('Illuminate\Http\Response')->status(),
// ], app('Illuminate\Http\Response')->status());
// }
return back();
}
}
我得到的第一个错误是Pusher:No callbacks on private user。[object htmldevelment]对于控制台上的Pusher:subscription\u ERROR
,这里我假设没有传递经过身份验证的用户的实例,所以我在app.blade.php文件中插入了这个-var user={{$user->id}}“
在使用npm run dev
编译我的app.js脚本之前。
现在,我可以得到auth user的一个实例,因为我在视图中对它进行了硬编码,但随后,我遇到了另一个错误-Pusher:No callbacks on private user.6对于Pusher:subscription\u error
。今天我一直在试着调试这个。拜托,我真的需要有人帮忙。多谢各位
哦,我在config/App.php中取消了App\Providers\BroadcastServiceProvider::class,
编辑:
在UserStatusEvent中。
--
<?php
namespace App\Http\Controllers;
use App\Events\UserStatusEvent;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['auth', 'profile'])->except('show', 'help');
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param string $user
* @return \Illuminate\Http\Response
*/
public function update(Request $request, User $user)
{
$data = $request->only(['first_name', 'last_name', 'middle_name', 'email', 'city', 'dob', 'gender', 'address']);
$user->update($data);
event(new UserStatusEvent(auth()->user()));
// if ($request->ajax()) {
// return response()->json([
// 'status' => 'Profile Update successful.',
// 'errors' => app('Illuminate\Http\Response')->status(),
// ], app('Illuminate\Http\Response')->status());
// }
return back();
}
}
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Pusher.logToConsole = true;
window.Echo = new Echo({
authEndpoint: 'http://localhost/penfs/public/broadcasting/auth',
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true
});
window.Echo.private(`user.${user}`)
.listen('UserStatusEvent', (e) => {
console.log(e.user.first_name);
console.log(e.user.email);
});
public $user;
public function __construct(User $user){
$this->user = $user;
}
public function broadcastOn(){
return new PrivateChannel('user.'.$this->user->id);
}