title: Trying to share data across views Laravel
body: <p>I am trying to share the username across my fixed blade which I am extending in other views. I am using the controller to verify my users and thereby passing the data to the views. However, I get an error saying </p>
  
  <pre><code>Undefined variable: username (View: 
  E:\LaravelProjects\adminLTE\resources\views\layout\fixed.blade.php) 
  </code></pre>
  
  <p>I have clearly passed the data using the View:share in my controller. What could be my possible error? </p>
  
  <p>My code is as follows:</p>
  
  <p><strong>controller.php</strong></p>
  
  <pre><code>    &lt;?php
  
  namespace App\Http\Controllers;
  
  use DB;
  use session;
  use App\User;
  use Carbon\Carbon;
  use Auth;
  use View;
  use Hash;
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Input; 
  use Redirect;
  use Illuminate\Http\Request;
  
  class mainController extends Controller
  {   
      //user login
      public function login(){
          return view('login');
      } 
  
      public function logs_in(Request $request){ 
          $email = $request-&gt;input('email');
          $password = $request-&gt;input('password');
  
          $hashedPassword = User::where('email', $email)-&gt;first();
  
  
          $role_type = User::select('role_type')-&gt;where('email', $email)-&gt;get();
          $username = User::select('name')-&gt;where('email', $email)-&gt;get();
  
              if(Hash::check($password, $hashedPassword-&gt;password)){ 
                  if($role_type == '[{"role_type":"Administrator"}]'){ 
                      $request-&gt;session()-&gt;put('admin_name', $username );
                      View::share('username', $email);
                      return redirect()-&gt;route('dashboard');
                  } else if ($role_type == '[{"role_type":"Staff"}]') {
                      $request-&gt;session()-&gt;put('success');
                      return redirect()-&gt;route('staff');
                  } else if ($role_type == '[{"role_type":"User"}]') {
                      $request-&gt;session()-&gt;put('success');
                      return redirect()-&gt;route('user_dashboard');
                  };
              } else {
                  return redirect()-&gt;route('login')-&gt;with('login_error', 'Invalid 
                  credentials entered');
              };
      }
  </code></pre>
  
  <p><strong>fixed.blade.php</strong> I am getting the error from this view</p>
  
  <pre><code> &lt;li class="dropdown user user-menu"&gt;
      &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;
        &lt;img src="{{ asset ('images/logo.png')}}" class="user-image" alt="User Image"&gt;
        &lt;span class="hidden-xs"&gt;&lt;i&gt;{{ $username }}&lt;/i&gt;&lt;/span&gt;
      &lt;/a&gt;
      &lt;ul class="dropdown-menu"&gt;
        &lt;!-- User image --&gt;
        &lt;li class="user-panel"&gt;
          &lt;p align="center"&gt;
            &lt;img src="{{ asset ('images/logo.png')}}" style="width:100px;height:100px;" alt="User Image" &gt;
            &lt;h4 align="center"&gt;{{ $username }}&lt;/h4&gt;
          &lt;/p&gt;
        &lt;/li&gt;
  </code></pre>