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

CDNxL's avatar
Level 1

How pass objects to Blade directive?

I've created a Blade directive

Blade::directive('img', function ($object) {
     //
});

How can I pass an object to the function closure? it accepts only strings.

@img($object)

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

blade is building a string that will be inserted into your view. It does not run when the blade file is processed.

The string that is passed through needs to be returned from your blade to construct the runtime expression

1 like
CDNxL's avatar
Level 1

Ok, now I've understood. Thanks.

Please or to participate in this conversation.