Add PHP libraries to Laravel 5 projects

If you want to add an additional PHP library in your Laravel 5 projects just follow these two steps:

1. Add the library with composer

For example, here we add the Facebook SDK library:

$ composer require facebook/php-sdk-v4

2. Just use it in your PHP code

The library you added via composer is autoloaded in your project so you can now use it in you PHP code.

Here we are using the Facebook class, added with the Facebook’s library, into a PHP file in the Laravel project:

<?php

namespace App;

class MyExampleClass
{
  public function facebookMethod()
  {
    $fb = new \Facebook\Facebook([
      'app_id' => '{app-id}',
      'app_secret' => '{app-secret}',
      'default_graph_version' => 'v2.2',
    ]);

    // ...
  }

}

That’s all.

References

https://laracasts.com/discuss/channels/general-discussion/using-non-laravel-composer-package-with-laravel
http://wern-ancheta.com/blog/2015/05/09/getting-started-with-lumen/

Categories

Category BootstrapCategory CoffeescriptCategory DrupalCategory GravCategory HTMLCategory JavascriptCategory JoomlaCategory jQueryCategory LaravelCategory MagentoCategory PHPCategory SharePointCategory SpringCategory ThymeleafCategory WordPressCategory Workflow

Comments

Developed and designed by Netgloo
© 2017 Netgloo