Roots Discourse

Pass anonymous functions to views from Composers

Has anyone tried this @alwaysblank suggestion successfully?

I tried:

// MyComposer.php
public function override()
{
    return [
        'test' => function() {
            return 'test';
        }
    ]; }
// my-view.blade.php
{{ test() }}

But I get

Call to undefined function test()

It returns it as a variable. You have to call it that way, as the original suggestion indicates:

{{ $test() }}
2 Likes