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]);
CodePudding user response:
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
}