Laravel & Lumen with Informix DB

I was looking to try and work with Lumen to create a API frontend for few services we have, and the problem I had was to make Laravel/Lumen to work with Informix DB. I found a small package called laravel-ifx which seems to answer my need, but it was not updated to support Laravel 5.7, trying to install it will result with a conflict. Seems like few others had the same problem and forked the repo, and updated the composer.json file to remove/change the version requirement from 5.2.* to 5.*.

  "require": {
     "php": ">=5.5.31",
-     "illuminate/support": "5.2.*",
-     "illuminate/database": "5.2.*",
-     "illuminate/pagination": "5.2.*",
+     "illuminate/support": "5.*",
+     "illuminate/database": "5.*",
+     "illuminate/pagination": "5.*"
   },

Also, Laravel from version 5.6 support auto loading service providers, so I also added this lines to my composer file,

  "extra": {
    "laravel": {
      "providers": [
        "Poyii\\Informix\\InformixDBServiceProvider"
      ]

Laravel

And then in my project I add a remote repo to point to my version of the package on github

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/isoc-il/laravel-ifx"
        }
    ],

and then require the package

$ composer require isoc-il/laravel-ifx:dev-master

and next will publish the config file for informix

$ php artisan vendor:publish

 Which provider or tag's files would you like to publish?:
  [0 ] Publish files from all providers and tags listed below
  [1 ] Provider: BeyondCode\DumpServer\DumpServerServiceProvider
  [2 ] Provider: Fideloper\Proxy\TrustedProxyServiceProvider
  [3 ] Provider: Illuminate\Foundation\Providers\FoundationServiceProvider
  [4 ] Provider: Illuminate\Mail\MailServiceProvider
  [5 ] Provider: Illuminate\Notifications\NotificationServiceProvider
  [6 ] Provider: Illuminate\Pagination\PaginationServiceProvider
  [7 ] Provider: Laravel\Tinker\TinkerServiceProvider
  [8 ] Provider: Poyii\Informix\InformixDBServiceProvider
  [9 ] Tag: config
  [10] Tag: laravel-errors
  [11] Tag: laravel-mail
  [12] Tag: laravel-notifications
  [13] Tag: laravel-pagination
 > 8

Copied File [/vendor/isoc-il/laravel-ifx/src/config/informix.php] To [/config/informix.php]
Publishing complete.

Now update the .env file with the require info to connect to the DB

DB_CONNECTION=informix
DB_HOST=hostname
DB_SERVICE=9088
DB_DATABASE=store
DB_USERNAME=ifxu
DB_SERVER=ol_db
DB_PASSWORD=xxxxxx

Lumen

`laravel-ifx` can work with Lumen but it require a bit more manual work. Lumen is missing a helper function which exist in Laravel, so we will have to define it manually.

create a new file in your project called “app/Support/helpers.php” and add this lines to it.

<?php

if (!function_exists('config_path')) {
    /**
     * Get the configuration path.
     *
     * @param  string $path
     * @return string
     */
    function config_path($path = '')
    {
        return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
    }
}

create the config folder on the project root dir and copy the informix.php file from laravel-ifx/config folder to it.

Next will update the bootstrap/app.php file to allow the use of the new provider,

enable $app->withFacades(); and $app->withEloquent(); and add the line $app->configure('informix');  after them, and then register the provider with $app->register(Poyii\Informix\InformixDBServiceProvider::class); 

Resources

  • https://laracasts.com/discuss/channels/lumen/fixing-apparent-laravel-package-incompatibility-with-lumen
  • https://getcomposer.org/doc/03-cli.md#modifying-repositories

 

 

You may also like...

1 Response

  1. Javier says:

    Thank you very much!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *