0
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!'];
}

I get this error :

Argument 1 passed to App\Http\Controllers\ChatsController::sendMessage() must be an instance of Illuminate\Http\Request, integer given, called in C:\xampp\htdocs\ScrimWithMe\app\Http\Controllers\ChatsController.php on line 77 and defined

9
  • 1
    public function sendMessage(Request $request,$whatRelation) you are passing integer for first parameter it should be a request. Commented May 19, 2017 at 2:01
  • Hmm can you explain little more what i need to change i don't understand... Commented May 19, 2017 at 2:04
  • your passing single argument only $this->sendMessage($whatRelation); Commented May 19, 2017 at 2:05
  • 1
    pass like this $this->sendMessage(Request $request,$whatRelation); Commented May 19, 2017 at 2:09
  • 1
    pass like this $this->sendMessage(Request $request,$whatRelation); and access like this public function sendMessage($request,$whatRelation) Commented May 19, 2017 at 2:15

2 Answers 2

3

you have two parameters needed for the sendMessage function .. but you're just passing one parameter ..

what you can do is add another parameter in your chat function chat like

public function chat(Request $request, $id,$team1,$team2){
    ....
    $this->sendMessage($request,$whatRelation);
}

then add a parameter in said function and that should do it ..

Sign up to request clarification or add additional context in comments.

Comments

0

@Demonyowh explain all that why you get this error

I think it's factory design pattern there are two ways to solve your problem

  • If your method not used on any other place then remove first parameter and declare class on next line

    METHOD(){
      $request = new Request();
      // your code;
    }
    
  • Declare this class parameter in your __construct method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.