From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The active record pattern in action

The active record pattern in action - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

The active record pattern in action

- Now let's use Eloquent, which is the ORM or, Object Relational Mapper, for the layer of our framework. You'll see that once again our index.php file is very simple. We're not doing any queries or configuration here. Which is good. Like many of the examples in this course I used Composer to install the supporting libraries in the vendor folder. You shouldn't have to install any additional libraries to make use of these examples. In user.php you'll see we really don't have to do much beyond setting up the database connection. We configure it with the database information we need and the Eloquent RM handles the rest. By default it will handle mapping all the fields from the database to an object or the other way around. There's not much else we need to do. Notice that we didn't even have to specify which table to use. By default Eloquent will assume that the table name is the plural of the class name. So if you have a class named Project it will assume the data is in the Projects…

Contents