0

I need help figuring out what I'm doing wrong. I'm building a chat where on the right side I have the users and when clicking on the user opens the respective chat.

In the users on the right I put the following HREF:

<a href="{{route('chat.index', ['id'=>$item->id])}}">

Which then shows the following link on the page:

/Chat?id=10

I put in the view if there is id shows the chat.

@if ($id)

But don't come here. I can't get the IF to be true.

In the controller I have the following code, but I don't think it's wrong.

$outroUser = null;

if($id){
    $outroUser = utilizador::findOrFail($id); 
}

$tabela = utilizador::orderBy('id', 'desc')->get();

return view('painel-admin.chat.index', ['itens' => $tabela, $outroUser]);

1 Answer 1

1

To get id param you can try following in your controller

if ($request->has('id')) {
    $outroUser = utilizador::findOrFail($request->query('id'));
}

Do not forget to add Request object into your controller function params

use Illuminate\Http\Request;

public function yourController(Request $request) {
   //Code
}
Sign up to request clarification or add additional context in comments.

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.