N
N
naneri2015-08-05 10:46:29
Laravel
naneri, 2015-08-05 10:46:29

Where does Eloquent connect in Laravel?

I decided to study the architecture of Laravel - one of the questions that I could not find an answer to: where is Eloquent connected in laravel?
If you cut it in another framework as a library, its initialization goes like this:

use Illuminate\Database\Capsule\Manager as Capsule;  

$capsule = new Capsule; 

$capsule->addConnection(array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'test',
    'username'  => 'test',
    'password'  => 'l4m3p455w0rd!',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => ''
));

$capsule->bootEloquent();

But I didn't find it in Laravel itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2015-08-05
@naneri

It's a little more complicated there.
The Illuminate\Database\DatabaseServiceProvider registers the DatabaseManager, ConnectionFactory, and EloquentFactory. And then they love each other there.
Illuminate\Database\Capsule\Manager is not used in Laravel itself, it is invented for external projects /
Illuminate\Database\Capsule\Manager essentially accepts a DatabaseManager which in turn accepts a ConnectionFactory which manages the connection depending on the config.

V
Vyacheslav Plisko, 2015-08-05
@AmdY

You need to be careful with the laravel architecture, there are a lot of bad practices that are used to simplify the api and syntactic sugar.
In this case, you need to dig into the laravel.com/docs/5.1/container container to understand how services are created and stored, how the Laravel facade works.
There are good pattern slides inside Laravel www.slideshare.net/sparksphill/software-design-pat...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question