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

DevCodeForce's avatar

How to access slots and attributes with Blade Component Classes

I want to achieve the following:

I want to create a package with my own components. So for instance I have a card component.

The card component would be called with: Title Lorem Ipsum

Basicly I want to set an attribute in my component class that checks if the header slot is present and then add an attribute divideClasses='divide-y divide-blue-200" that I can return in the card.blade.php

If I follow the example(https://laravel.com/docs/8.x/blade#using-attributes-slots-within-component-class) and use a return function in the render() class and I add a $data['divideClasses'] in the return function, the variable is not reaching the blade file.

What is the correct way to achieve this?

0 likes
1 reply
meduz's avatar

Answering late, but from what I’ve tried, you don’t need to pass data to the view from the render function. Instead, public properties of your component class are automatically made accessible to the component view, as described in the “Passing Data To Components” part of the docs.

Please or to participate in this conversation.