public function chat($id,$team1,$team2){
$relation=Crelation::where('match_id',$id)->where('first_team_id',$team1)->where('second_team_id',$team2)->first();
if($relation == null){
$data=[
'match_id'=>$id,
'first_team_id'=>$team1,
'second_team_id'=>$team2
];
$rel= Crelation::create($data);
$whatRelation=$rel->id;
$this->sendMessage($whatRelation);
}else{
$whatRelation=$relation->id;
$this->sendMessage($whatRelation);
}
return view('chat',compact('whatRelation'));
}
public function sendMessage(Request $request,$whatRelation)
{
$id=(int)$whatRelation;
$user = Auth::user();
$message = $user->messages()->create([
'message' => $request->input('message'),
'crelation_id'=>$id
]);
broadcast(new MessageSent($user, $message))->toOthers();
return ['status' => 'Message Sent!'];
}
我收到此错误:
参数1传递给 App \ Http \ Controllers \ ChatsController :: sendMessage()必须是一个 Illuminate \ Http \ Request的实例,给定的整数,调用 C:\ XAMPP \ htdocs中\ ScrimWithMe \程序\ HTTP \控制器\ ChatsController.php 在第77行并定义
答案 0 :(得分:3)
chat
函数需要两个参数..但您只是传递一个参数..
您可以做的是在public function chat(Request $request, $id,$team1,$team2){
....
$this->sendMessage($request,$whatRelation);
}
功能聊天中添加另一个参数,例如
container
然后在所述函数中添加一个参数,应该这样做..
答案 1 :(得分:0)
@Demonyowh解释了为什么会出现此错误
我认为factory design模式有两种方法可以解决您的问题
如果你的方法没有在任何其他地方使用,那么删除第一个参数并在下一行声明类
METHOD(){
$request = new Request();
// your code;
}