12
votes

When using Laravel I am aware of the steps to follow to use a 3rd party library in my project using composer:

  1. Add the package to composer.json:

    "require": { "zizaco/confide": "3.2.x" }

  2. Run composer update to install the package

  3. Add to the providers and alias arrays in config/app.php

I am trying to do the same with highchartsphp. Installing via composer is simple enough but there are no instructions on how to use this package with Laravel. How to load the correct file and how to I instantiate the class as described in the readme? Is it just a case of adding it to the providers and aliases and then doing $chart = new HighChart(); wherever I want?

1

1 Answers

20
votes

This is not a Laravel package, so you don't have Service Provider nor Alias to setup, but this is a PHP package and since you use Composer to install it, it is already autoloaded, so you can just:

Add the package to your composer.json:

{
    "require": {
        "ghunti/highcharts-php": "~2.0"
    }
}

Run

composer dumpautoload

And instantiate it:

$chart = new Ghunti\HighchartsPHP\Highchart();

Or use it in the top of your php:

use Ghunti\HighchartsPHP\Highchart;

And you should be able to:

$chart = new Highchart(Highchart::HIGHSTOCK);

Anywhere in your project and it should work.

You can create an alias in app/config/app.php for it if you prefer to use it this way:

'Highchart' => 'Ghunti\HighchartsPHP\Highchart'

But you will still have to instantiate it

$chart = new Highchart();

You won't able to use it as in Laravel

Highchart::doWhatever();

Unless you create a ServiceProvider yourself, of course.