I've recently started learning Laravel, and I noticed that the DB object is passed via use
, allowing access to the object in any created methods. I'm guessing it's done by storing the database connection information as static properties, or referencing the variables internally.
Right now, in my own (non-Laravel) code, I have a PDO and MySQL object created in a file loaded on each page, which I end up importing into any functions/methods via global
, but I'm realizing this can be a bit tedious. Is there a better way to do this? The only thing I can think of is to create an object with a static property that is an array of DB objects, and a static function that returns them, so I can access them as DB::use('mysql')->query
or what not.