title: Laravel - how do you access App object in a custom class?
body: <p>I have a custom class in app/libraries/data/Data.php where i want to return a connection to a database.</p>
  
  <p>The problem is i need to dynamically load a database that doesn't(and can't) exist in the config file.</p>
  
  <p>I found a nice solution, and to be honest it was exactly what i was hoping for, but it seems i cant access the App object from there.</p>
  
  <pre><code>&lt;?php
  namespace libraries\data;
  use DB;
  
  class Data 
  {
  
      public function db($name, $firma = false)
      {
  
          if ($name == 'firma') {
  
              $config = App::make('config');
              $connections = $config-&gt;get('database.connections');
  
              $newConnection = $connections[$config-&gt;get('database.firma_%s')];
  
              $name = sprintf('firma_%s', $firma);
              $newConnection['database'] = $name;
  
              App::make('config')-&gt;set('database.connections.'.$name, $newConnection);
          }
  
          return DB::connection($name);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Update: of course i tried "use App;" (d`oh) and of course it didn't work. And of course it works now. </p>