title: laravel get the id of the currently logged in user using Eloquent auth
body: <p>I'm using <code>Laravel 4.2</code> in my web application and I'm trying to get the id of the currently logged in user. This is how i have done it in <code>UserController.php</code>.</p>
  
  <pre><code>if(Auth::attempt($credentials)){
  
    $user = Auth::user();
    return Redirect::to('admin/profile');
  
   }else{
        return Redirect::to('login');;
       }
  </code></pre>
  
  <p>and this is my <code>route.php</code>:</p>
  
  <pre><code>Route::group(['prefix' =&gt; 'admin'], function()
   {
     Route::resource('profile', 'AdminController', ['as'=&gt;'package']);
  
    });
  </code></pre>
  
  <p>Now In the <code>AdminController.php</code> I have the method index() where I'm trying to get the id of the current loged in user. After the redirection from login page I can get the id of the user but when I refresh my profile page many times I lost the id of the user and he seems to be logout I get only 'sorry'.
  this is my index method:</p>
  
  <pre><code>if (Auth::check()){
  
             echo 'ok';
             echo $id = Auth::user()-&gt;id;
  
  
          }else{
              echo 'sorry';
          }
  </code></pre>
  
  <p>How can I fix that? is it related to <code>laravel auth</code> with <code>Eloquent</code>? How can I get the id of the logged in user?</p>
  
  <p>--edit---
  If I just use <code>Route::post</code> I don't get this problem and I can easily get the user id.But I want to use <code>Route:Resource</code> with index,edit,update methods.</p>