CodeIgniter Forums

Full Version: Codeigniter 4 using Eloquent
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys, howto install and use eloquent in codeigniter 4, this is important for me, thanks a lot
This works for me and has probably been copied and pasted from elsewhere):
Load eloquent libraries via composer
All my Eloquent Model classes are in app/Models/Eloquent folder
In app/Config/Database.php - at the end of the constructor:
        $capsule = new Capsule;

            'driver'    => 'mysql',
            'host'      => $this->default['hostname'],
            'database'  => $this->default['database'],
            'username'  => $this->default['username'],
            'password'  => $this->default['password'],
            'charset'  => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => $this->default['DBPrefix'],

        // Set the event dispatcher used by Eloquent models... (optional)
        $capsule->setEventDispatcher(new Dispatcher(new Container));

        // Make this Capsule instance available globally via static methods... (optional)

        // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
        //require each model file
        foreach(glob(APPPATH."/Models/Eloquent/*.php") as $file){
            require $file;
This link does not work.
(07-07-2020, 01:34 AM)marcogmonteiro Wrote: [ -> ]This link does not work.