Laravel How to load a third-party class library

Source: Internet
Author: User
Tags autoload
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

mkdir app/libraries

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:

Composer Dump-autoload

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);
Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.