Is there a way to have a class method return a Flux component? My work around was to create my own blade component to hold the Flux tags then return view('my-flux-component'). But can I just call Flux directly without concatenating a string in the method?
For example, I have a list of Posts I want to add an action menu: View, Delete, etc. I want to have an action class that handle() but also render the menu item.
// Example
class Post
{
public $actions = [
Actions\ViewPost::class,
Actions\DeletePost::class
];
}
//Example
class Actions\ViewPost
{
public static function menuItem()
{
// What I'm trying to achieve
return Flux::menuItem( $attributes... );
// or...
return view('flux::menu.item', [...]);
}
}
The code above is just an example of the syntax I'm looking for, similar to how the Flux docs explain Flux::modal->close().
I understand that's what blade is for, but Flux is already a view/component and putting it in another view/component seems redundant. If i wanted to render a Flux badge it'd be nice to just return the badge instead of a whole separate view.
The first return as a static method probably wouldn't work well if to require the additional wrappers. However, i'm not sure how to reference the views path to flux components. By convention, return view('flux.menu.item') should work but it does not, even as a namespace flux::menu.item.
My solution so far is a Volt component with blade @if conditionals which i don't like. However my small project it's not a dealbreaker.