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() }}
3 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.