Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Make attributes available within render method #32978

Merged
merged 3 commits into from
May 26, 2020

Conversation

taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented May 26, 2020

Currently $this->attributes is null within a component's render method. This solves that by allowing components to return a Closure from render to defer the template building... which allows you to do some pretty funky stuff.

public function render()
{
    return function ($data) {
        // return $data['attributes'];
        // return $this->attributes;
    };
}

@taylorotwell taylorotwell merged commit a2668ed into 7.x May 26, 2020
@GrahamCampbell GrahamCampbell changed the title Make attributes available within render method [7.x] Make attributes available within render method May 27, 2020
@driesvints driesvints deleted the attributes-in-render branch May 27, 2020 11:19
@Pennywise96
Copy link

Hello,
how can I get this to work?

If I put the return function ($data) in my component render function, I get this error:
syntax error, unexpected '}', expecting ';'

Did I forget something there?

@driesvints
Copy link
Member

@Pennywise96 this hasn't been released yet. Next Tuesday it will be.

@Pennywise96
Copy link

@driesvints I have now updated to version 7.14.0, but I still get the same error.
Did I forgot something?

@mennovanhout
Copy link

@driesvints I have now updated to version 7.14.0, but I still get the same error.
Did I forgot something?

As your error states. You're just using it wrong it seems. Probably you made a syntax error, But your snippet is to small to give any more details.

@Pennywise96

This comment has been minimized.

@BrandonSurowiec

This comment has been minimized.

@laravel laravel locked as off-topic and limited conversation to collaborators Jun 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants