use function Roots\view;
...
public function with()
{
return [
...
'list' => $this->list(),
];
}
public function list()
{
return view('components.some-list', [
'users' => ['Stipe', 'Frane', 'Mate'],
])->render();
}
And in some-list.blade.php
<ul>
@foreach($users as $user)
<li>{{ $user }}</li>
@endforeach
</ul>
but when I call it in page template with {!! $list !!} I get exhausted memory.
Second, there are better ways to render a component into your view. Rather than returning it from a Composer, you can render the component using the Blade Component Template Tag. Using template tags is a cleaner solution and easier to maintain than having your view render from inside of the App composer. You can use wp acorn make:component UserList to scaffold out the boilerplate component files.