Adding Third party library to Laravel

Viewed 8382

I have an RSA algorithm Library giving to me by a payment gateway and When I do a

include (app_path().'/PaymentGateway/Crypt/RSA.php');

this and try to make an object as $rsa = new Crypt_RSA(); this it gives me and error saying

Class 'App\Http\Controllers\Crypt_RSA' not found

I tried including it in web.php and making an object it worked the problem occur when I try to include it in a Controller.

3 Answers

This is what I did. Oh and a little back ground I use to have this in Laravel 4, PHP 5, jpgraph 2.

I am using jpgraph 4.1 on Laravel 5.5 using PHP 7.

  1. Created a folder under app called jpgraph
  2. Placed the src folder that is in the tarball of jpgraph in that folder
  3. Created file call Graph1.php, is my code using jpgraph, with the class Custom_GraphsJM in the jpgraph folder.
  4. In composer.json added "app/jpgraph/Graph1.php" to the "classmap"

    "autoload": {
      "classmap": [
        "database/seeds",
        "database/factories",
        "app/jpgraph/Graph1.php"
      ],
      "psr-4": {
        "App\\": "app/"
      }
    },
    
  5. In the application folder:

    composer dump-autoload

  6. Checked the autoload_classmap.php and I have

    'Custom_GraphsJM' => $baseDir . '/app/jpgraph/Graph1.php',

  7. In my Model at the top I have

    use Custom_GraphsJM;

  8. To create a class

    $Two_Graphs_Temp = new Custom_GraphsJM();

Related