![]() ![]() ![]() One of the major advantages of Laravel 5 (and PSR-4) is that all the class names and namespaces should resemble the file system so everything should be pretty intuitive. It might seem like a bit of effort to find if the facade still provides access to a method, but using a good IDE (PHPStorm in my case) and knowing the basics about it (which I hopefully described here) means you can look these things up in less than a minute. I opened this file and found the method you're looking for. It's also in the same namespace as the DatabaseManager I'm looking at. Looking at the connection method, I can see from the PHPdoc block on this method that it returns a \Illuminate\Database\Connection which is a PSR-4 class name (again). Either ways it sometimes give me a headache, specially as i just started learning. I didn't find it, but I did find a _call magic method that will proxy to another object accessed with $this->connection(). May be ive missed some configurations on Laravel or phpstorm or both, may be this issue is in only phpstorm v9. I opened up the DatabaseManager and looked for the method getTablePrefix. DatabaseManager is not specifically namespaced in the service provider and therefore must exist in the same namespace, which means it'll be in the same folder in the source. Investigate the service that the facade is fronting. I can see in this service provider that "db" is registered as a DatabaseManager. This is also a PSR-4 class name so you can find the file pretty easily in the Laravel source here There's a service called Illuminate\Database\DatabaseServiceProvider which is the only thing I saw related to database, so I guessed that. In order to find what registers this service, I had to guess the service provider which is registered in the config/app.php file. This simply sets the facade to point to an object in the " Service Container" named "db" That points to this file in the Laravel source. First, I accessed the facade definition using the PSR-4 class name from step 1. This is a little more tricky and requires a little bit of intelligent guesswork. composer require -dev barryvdh/laravel-ide-helper After, run: php. I would recommend you 100 to switch to PHPStorm, it is paid, but if you or your company can afford the license, you will not have these issues and you will get a big help. The config/app.php file and refer to a PSR-4 namespace of theĬheck what class the facade points at. Do you have the corresponding use IlluminateSupportFacadesValidator on the top of your file. In this CreatorSeries, using all of the knowledge Ive acquired over the years of building and maintaining Shift, Ill show you how to automate many of your every-day development. Using \DB::getTablePrefix() or placing use \DB as DB at the top of the document solves the problem.Īs requested, I will describe the steps I took to ensure the method was still accessible through the facade:Ĭheck the facade is still there. Im the founder of Laravel Shift, a popular service that provides automatic upgrades for your Laravel applications. As discussed in the comments, the issue was not that the method was not accessible from the facade, but rather the facade was not being called correctly in the base namespace. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |