'How to determine global variable in Blade template?

I try to determine a global variable in template blade:

global $result_view;

Below this I try call this:

 <?=$result_view?>

And get error: Undefined variable: result_view ()



Solution 1:[1]

In Controller or Service provider , you can add

View::share('result_view', 'SomeValue');

in any Blade template in your project you can use,

{{ $result_view }}

Solution 2:[2]

One way to do it is to define your variable in a config file and then you'll be able to get this var in all views, controllers etc.

{{ config('myConfig.someVariable') }}

Also, you can use view composer to set global variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2