First of all, we need to install the required component via composer:
Let’s create our index.php file to start experimenting:
Capsule class is a sort of helper to work with a database. It uses Laravel’s Container inside to manage connections and to create a DatabaseManager object.
The next step is to add a connection with the specified settings (driver, login, password):
AddConnection() method adds specified to the container’s ['config']['database.connections'] array. Then bootEloquent() passes a DatabaseManager instance as a connection resolver to the Eloquent\Model class:
So, this was our setup step and now we are ready to start implementing models. We start with creating a special folder models for them. And lets create a User model:
And that is all! Now we can create and use Eloquent models in our application. The only required steps are:
Create a capsule manager and add a connection to it.
Boot eloquent on the capsule manager.
Create and use Eloquent models by extending Eloquent\Model class.