Listing model
We've now successfully created a database table for our listings and seeded it with mock listing data. How do we access this data now from the Laravel app?
We saw how the DB
facade lets us execute queries on our database directly. But Laravel provides a more powerful way to access data via the Eloquent ORM.
Eloquent ORM
Object-Relational Mapping (ORM) is a technique for converting data between incompatible systems in object-oriented programming languages. Relational databases such as MySQL can only store scalar values such as integers and strings, organized within tables. We want to make use of rich objects in our app, though, so we need a means of robust conversion.
Eloquent is the ORM implementation used in Laravel. It uses the active record design pattern, where a model is tied to a single database table, and an instance of the model is tied to a single row.
To create a model in Laravel using Eloquent ORM, simply extend the Illuminate\Database\Eloquent\Model
class using Artisan...