title: Laravel 5.4 : Best practice to parse variable to a view
body: <p>For example, I want to add a variable in my default view (default.blade.php)</p>
  
  <p>I can of course, define my variable directly into the view file, like this :</p>
  
  <pre><code>@php ($user = Sentinel::getUser())
  </code></pre>
  
  <p>But this is not recommended.</p>
  
  <p>Should I add it on AppServiceProvider.php ? (<a href="https://laravel.com/docs/5.4/views#sharing-data-with-all-views" rel="nofollow noreferrer">https://laravel.com/docs/5.4/views#sharing-data-with-all-views</a>)</p>
  
  <p>But with which call ? Like this :</p>
  
  <pre><code>public function boot()
      { $user = Sentinel::getUser(); }
  </code></pre>
  
  <p>This get : Undefined variable: user</p>
  
  <pre><code>public function boot()
      { View::share('user', Sentinel::getUser()); }
  </code></pre>
  
  <p>This get Trying to get property of non-object, so Sentinel is not truly declare</p>
  
  <p>Or in the a controller </p>
  
  <pre><code>public function __construct()
      {
          //user
          $user = Sentinel::getUser();
          view()-&gt;share('user',$user);            
  
      }
  </code></pre>
  
  <p>I also try this into my controller</p>
  
  <pre><code>public function boot()
      {
          return view('layouts/default')-&gt;with('user', Sentinel::getUser(););
      }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>public function boot()    {
          view()-&gt;composer('layouts.default', function($view)     {
              $view-&gt;with('user', Sentinel::getUser());
  
          });     
      }
  </code></pre>
  
  <p>Still get "Undefined variable: user"</p>