Question: In PHP, I used to define some variables in my `header.php` and use them in all my pages. How can I have something like that in Laravel?

I am not talking about `View::share('xx', 'xx' );`

Assume I want to have a variable which holds a number in it and I need this number inside all my controllers to calculate something.

Answer: 
Set a property on the `BaseController`, which should be located in your `controllers` directory.

Your controllers should extend the `BaseController` class and thus inherit its properties.
You could use [View Composers](http://laravel.com/docs/5.1/views#view-composers)

And instead of using the boot method described in the docs you could use:

```
public function boot()
{
    // Using class based composers...
    view()->composer(
        '*', 'App\Http\ViewComposers\ProfileComposer'
    );

    // Using Closure based composers...
    view()->composer('*', function ($view) {

    });
}

```

That would render whatever variables you declare with 

```
$view->with('yourVariableName', 'yourVariableValue');

```

to all the views in your app.

Here is a full example of how I used this in one of my projects.

**app/Providers/ComposerServiceProvider.php**

```
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider
{
     /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer(
            '*', 'App\Http\ViewComposers\UserComposer'
        );
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

```

**app/Http/ViewComposers/UserComposer.php**

```
<?php

namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;
use Illuminate\Contracts\Auth\Guard;

class UserComposer
{

    protected $auth;

    public function __construct(Guard $auth)
    {
        // Dependencies automatically resolved by service container...
        $this->auth = $auth;
    }

    public function compose(View $view)
    {
        $view->with('loggedInUser', $this->auth->user());
    }
}

```

Just remember that because you declared a new service provider it needs to be included in the 'providers' array in **config/app.php**