should be
{ { $userdetails['userid'] } }
in your view.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Trying to show variable in view with compact function.
in reurn i get the variable name and not the value:
{ { $userid } }
screenshot:
Am I writing a wrong syntax for blade engine maybe?
routes.php:
<?php
Route::get('/', function ()
{
return view('welcome');
});
Route::get('runchat','ChatController@runit');
chatcontroller.php:
<?php namespace App\Http\Controllers;
class chatcontroller extends Controller {
public function __construct()
{
$this->middleware('guest');
}
public function runit ()
{
$userdetails=[
"userid"=>"osherdo@gmail.com",
"password"=>'1234'];
return view('runchat',compact('userdetails'));
}
}
runchat.blade.php:
<html>
<body>
<p><b> Hello. This is a chat page.</b></p>
<b> you're { { $userid } } </b>
</body>
</html>
thank you guys.
Also, try seeing if you get the same output removing the space in between the curly braces
Please or to participate in this conversation.