Php Laravel事件错误,函数的参数太少
我试图广播一个没有成功的事件。我找不到问题所在,我也没有主意。我得到的错误是Php Laravel事件错误,函数的参数太少,php,laravel,events,broadcast,pusher,Php,Laravel,Events,Broadcast,Pusher,我试图广播一个没有成功的事件。我找不到问题所在,我也没有主意。我得到的错误是 "Too few arguments to function App\Events\ConversationUpdate::__construct(), 1 passed in /app/Events/ConversationUpdate.php on line 36 and exactly 2 expected" 我试图做的是在创建消息时,向聊天室广播一个事件,并用新消息实时更新聊天室 这是我的密码: 控制器: p
"Too few arguments to function App\Events\ConversationUpdate::__construct(),
1 passed in /app/Events/ConversationUpdate.php on line 36 and exactly 2 expected"
我试图做的是在创建消息时,向聊天室广播一个事件,并用新消息实时更新聊天室
这是我的密码:
控制器:
public function newConversationMessage(Thread $conversation, Request $request)
{
$user = Auth::user();
$message = Message::create([
'thread_id' => $conversation->id,
'user_id' => $user->id,
'body' => $request->body,
]);
$message->user;
broadcast(new ConversationUpdate($conversation->id, $message));
return $message;
}
活动:
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ConversationUpdate implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $conversationId;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($conversationId, $message)
{
$this->conversationId = $conversationId;
$this->message = $message;
}
public function broadcastOn()
{
return new ConversationUpdate('conversation-'.$this->conversationId.'-updated');
}
}
在函数
broadcastOn()
中,您应该返回如下内容
return new PrivateChannel('conversation-'.$this->conversationId.'-updated');
并且不是您所在的同一类的另一个实例(错误取决于您在构造函数中传递的单个参数的影响)