title: Laravel 4: Using $this and Undefined variable: user_id
body: <p>I'm new with Laravel and I have some problem </p>
  
  <p>First Problem: When I using $this-> in __construct function , and want to using it in a method Like this code:</p>
  
  <pre><code>// construct method
  public function __construct() {
          $this-&gt;user_id = Auth::user()-&gt;id_user;
  }
  // another method 
      public function index()
      {
  
  
          $this-&gt;data['files'] = DB::table('mhd_cloud_transfer_files')-&gt;distinct()
                      -&gt;where('mhd_cloud_transfer_files.to_transfer_file',$this-&gt;user_id )
                      -&gt;where('mhd_cloud_transfer_files.folder_transfer_file',0)
                      -&gt;orwhere(function($query){
                          $query-&gt;where('from_transfer_file', $this-&gt;user_id );
                          $query-&gt;where('to_transfer_file',0);
                      })
                      -&gt;join('mhd_cloud_files', 'mhd_cloud_files.id_file', '=','mhd_cloud_transfer_files.id_file')
                      -&gt;join('mhd_main_users', 'mhd_main_users.id_user', '=', 'mhd_cloud_files.author_file')
                      -&gt;paginate(25);
   }
  </code></pre>
  
  <p>this error :</p>
  
  <blockquote>
    <p>ErrorException: Undefined variable: user_id</p>
  </blockquote>
  
  <p>and another problem when I'm using $this-> in methods </p>
  
  <p>in same problem this error:</p>
  
  <blockquote>
    <p>Using $this when not in object context</p>
  </blockquote>
  
  <p><strong>This is All of my code (controller class)</strong>
  <a href="http://pastebin.com/eVbuknLd" rel="nofollow">http://pastebin.com/eVbuknLd</a></p>