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...

9 Responses

  1. Javier says:

    Thank you very much!!!!

  2. Angelo says:

    hi, work to laravel 6-7 version?

    • Rabin says:

      Laravel/Lumen 6 yes.
      but didn’t test 7 yet, I created a new branch called `staging`, you are welcome to test it.

  3. Gonzalo says:

    not working for mee 🙁

  4. Erick says:

    Amigo para laravel 8 funciona???? me podrias ayudar.

  5. Darwin Robles says:

    This package not work with Laravel 7 🙁 i have this errors:

    Problem 1
    – Root composer.json requires illuminate/support 5.2.*, found illuminate/support[v5.2.0, …, 5.2.x-dev] but these were not loaded, likely because it conflicts with another require.
    Problem 2
    – poyii/laravel-ifx[1.1.0, …, 1.1.1] require illuminate/support 5.2.* -> found illuminate/support[v5.2.0, …, 5.2.x-dev] but these were not loaded, likely because it conflicts with another require.
    – Root composer.json requires poyii/laravel-ifx ^1.1 -> satisfiable by poyii/laravel-ifx[1.1.0, 1.1.1].

    You can also try re-running composer require with an explicit version constraint, e.g. “composer require poyii/laravel-ifx:*” to figure out if any version is installable, or “composer require poyii/laravel-ifx:^2.1” if you know which you need.

    • Rabin says:

      Just tried it on a clean installation of Laravel 7, and it seems to work.

      Just added the repo to the composer file, and run `composer require isoc-il/laravel-ifx:dev-master`.

      Maybe you have another requirement which locking you and preventing the installation.

Leave a Reply to Erick Cancel reply

Your email address will not be published.