This article mainly introduces the method of loading third-party class library of Laravel, small series feel very good, now share to everyone, also give you a reference. Let's take a look at it with a little knitting.
Laravel Version: 5.5
There are many third-party class libraries that do not produce Composer, but are also loaded in a require way. For class libraries of this class, we can use them as long as we modify them in small granularity. I take the geetest and Mail service Sendcloud as an example.
Create a third-party SDK directory in the Laravel framework
Placement of geetest, Sendcloud SDK
After the official download of the relevant SDK, move to the App/libraries directory:
App/libraries/sendcloud-php-sdkapp/libraries/gt3-php-sdk
Note whether the. git directory exists in the respective SDK directory, and if so, remember to remove the. Git directory recursively. is the. Git directory in the SDK directory, never delete the error.
Modify the Composer.json file
... " AutoLoad ": { " Classmap ": [ " Database/seeds ", " Database/factories ", " app/libraries/ Sendcloud-php-sdk/lib ", " APP/LIBRARIES/GT3-PHP-SDK " ], " psr-4 ": { " app\\ ":" app/" } }, ...
Under AutoLoad-Classmap, App/libraries/sendcloud-php-sdk/lib and App/libraries/gt3-php-sdk are added.
Execute composer Command
Laravel Project Execution:
So it's done.
About using
For example, use in a Laravel controller
$objSendCloud = new \sendcloud (Api_user, api_key[, VERSION]), $objGeetestLib = new \geetestlib (captcha_id, Private_key);