Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

osherdo's avatar

Show variable in view with compact function

Trying to show variable in view with compact function.

in reurn i get the variable name and not the value:

{ { $userid } }

screenshot:

http://2.1m.yt/ULdquUy4A.png

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.

0 likes
5 replies
reny410's avatar

should be

 { { $userdetails['userid']  } }

in your view.

Ricus's avatar
Ricus
Best Answer
Level 3

Also, try seeing if you get the same output removing the space in between the curly braces

osherdo's avatar

@Ricus thank you. it worked when removing the space between the curly braces. It also works when there's no space between the curly braced and the variable. I have attached a screenshot for the correct code since it is not rendering well here.

http://2.1m.yt/jLZCmpFNQ.png

osherdo's avatar

@billmurrin thanks!! i saw those replies of yours and knew you where trying to write a proper answer. I tried many variations but could not succeed with it.

Please or to participate in this conversation.