Slim 4 + Eloquent ORM

Hi SlimFramework Friends :slight_smile:
I have created a project using the odan/slim4-skeleton - which is just awesome by the way (this had to be said :slight_smile: )

First - is there a reason why the Eoloquent ORM is not used any more? In the slim 3 it was very prominent and now it seems as everyone uses a different approach - is there a reason for that?

For me it was a working solution because I use the generate-model engine from laravel to reverse generate eloquent models of all existing db tables.
the result are eloquent models. So I am in the progress to figure out if I need eloquent to use them, or if I can use them with the integrated query-builder (in skeleton).
The skeleton uses array-objects as DTO Modles by my understanding. They are hand crafted I suggest. Does anyone know of a way to generate them?

I just mentioned the above to give you my reasoning for wanting to use eloquent :slight_smile:

So I tried to integrate Eloquent ORM into the slim 4 skeleton setup - but it did not work out for me.
Has anyone done this successfully (in the skeleton setup) and can point me into the right direction?

Thanks for your ideas :slight_smile:
all the best

Yeaa!! I figured it out. So for everyone else who wants to use eloquent orm + slim 4 - based on the odan skeleton here is my solution :slight_smile:

  1. create a file within the app/config and call it eloquent.php

    <?php use Slim\App; use App\Utility\Configuration; use Illuminate\Database\Capsule\Manager;

    return static function (App $app) {

     $container = $app->getContainer();
     $dbSettings = $container->get(Configuration::class)->get('db');
     // boot eloquent
     $capsule = new Illuminate\Database\Capsule\Manager;


  2. edit the file app/config bootstrap.php to run the eloquent capsule start
    I put it after starting the middleware

    // Register middleware
    (require DIR . โ€˜/middleware.phpโ€™)($app);

    // boot eloquent
    (require DIR . โ€˜/eloquent.phpโ€™)($app);

So that is it. This should work :slight_smile:

all the best

Hello Mario,
I think on one of the reasons why Eloquent is not enabled by default could be to point the developer to use clean architectures, instead to be coupled to an ORM from the beginning.

Hi Mario,
I wanted to try out Slim 4 skeleton with eloquent too, but I didnโ€™t manage to pull it off.
Also in my skeleton app there is no app/config directory. Is that something you created?
Can you send some example code, how you managed to do this?

thanks for the awesome information.