You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
Sometimes one might have need of rendering a blade component directly from say a controller or maybe a customized component instance from a model method.
The reason why this fails is because the $attributes variable is never instantiated when the component is rendered directly.
To get around this one might just pass an attribute variable from the view method, however this also fails due to the attributes variable needing to be an instance of ComponentAttributeBag.
My current solution - albeit a poor one - is to have a helper method instantiate an AnonymousComponent and then proceed to render that:
Keen for this. What would we want the API to look like? I'm not sure it warrants a whole new helper, but maybe a new method on the Illuminate\View\Factory class, so it could be used like this:
This new Illuminate\View\Factory::component($name, $attributes, $slots) method would ultimately return a string via the existing renderComponent method.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Sometimes one might have need of rendering a blade component directly from say a controller or maybe a customized component instance from a model method.
For example:
This works for simpler components; however, if the component looks like the following, it fails:
The reason why this fails is because the
$attributes
variable is never instantiated when the component is rendered directly.To get around this one might just pass an attribute variable from the view method, however this also fails due to the attributes variable needing to be an instance of
ComponentAttributeBag
.My current solution - albeit a poor one - is to have a helper method instantiate an
AnonymousComponent
and then proceed to render that:It would be nice if there was a built in solution to this use case and one that also allowed for rendering of class based components.
I realize this might be a really niche case, but I have not found any other way to re-use the code from the blade components outside a view file.
The text was updated successfully, but these errors were encountered: