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

devianvisuals's avatar

Not working "Short Attribute Syntax" component in blade-template

Laravel v9.32.0 (PHP v8.1.5)

Someone could help me please why is the "Short Attribute Syntax" component in blade template is not working?

Why I can't use it even if I run composer update or installed again a laravel project?

App Component: app\View\Components\ShortAttributeSyntax.php

public $userId;
public $name;

public function __construct($userId, $name)
{
    $this->userId = $userId;
    $this->name = $name;
}

public function render()
{
    return view('components.short-attribute-syntax');
}

Component: resources\views\components\short-attribute-syntax.blade.php

<div>
    ID: {{ $userId }} <br>
    Name: {{ $name }}
</div>

View: resources\views\app-short-attribute-syntax.blade.php

@php
    $userId = 328;
    $name = 'Adrian';
@endphp

<h3>Passing Data to component</h3>
{{-- Working --}}
<x-short-attribute-syntax :userId='$userId' :name='$name'/>

<h3>Short Attribute Syntax</h3>
{{-- Not working --}}
<x-short-attribute-syntax :$userId :$name />
0 likes
28 replies
Sinnbeck's avatar

Please format your code by adding ``` on the line before and after it

1 like
devianvisuals's avatar

@Sinnbeck What is the answer for this sir? I can't update my post :'( Question: What would a programmer say to the "world"?

devianvisuals's avatar

@Sinnbeck My Laravel project is updated to Laravel v9.32.0 (PHP v8.1.5) and still not working sir. Do you other idea about this sir?

devianvisuals's avatar

@Sinnbeck No error and result sir

@php
    $userId = 328;
    $name = 'Adrian';
@endphp

<h3>Short Attribute Syntax</h3>
{{-- Not working --}}
<x-short-attribute-syntax :$user-id :$name />
tykus's avatar

@devianvisuals this is not a good attribute (or variable name)

:$user-id

Try camelCase or snake_case instead:

:$userId // like your variable defined earlier
// or
:$user_id
devianvisuals's avatar

@Sinnbeck

public $userId;
public $name;

public function __construct($userId, $name)
{
    $this->userId = $userId;
    $this->name = $name;
}												
tykus's avatar

@devianvisuals what is the component actually getting:

public function __construct(...$args)
{
    dump($args);
devianvisuals's avatar

@tykus

dump($userId);
dump($name);

Results:

<x-short-attribute-syntax :userId='$userId' :name='$name'/>

Dump Output:

"328" // app\View\Components\ShortAttributeSyntax.php:30

"Adrian" // app\View\Components\ShortAttributeSyntax.php:31

<x-short-attribute-syntax :$userId :$name />

Dump Output:

None

devianvisuals's avatar

@tykus

dump($userId);
dump($name);

Results:

<x-short-attribute-syntax :userId='$userId' :name='$name'/>

Dump Output:

"328" // app\View\Components\ShortAttributeSyntax.php:30

"Adrian" // app\View\Components\ShortAttributeSyntax.php:31

<x-short-attribute-syntax :$userId :$name />

Dump Output:

None

devianvisuals's avatar

@tykus Yeah I thought I'm the only one who got this error or I'm just a noob in coding here

Sinnbeck's avatar

@devianvisuals Happy to help. It seems that it should work now. If not then show what you are getting :)

1 like

Please or to participate in this conversation.