Eloquent: Getting Started
- Introduction
- Defining Models
- Retrieving Models
- Retrieving Single Models / Aggregates
- Inserting & Updating Models
- Deleting Models
- Query Scopes
- Events
Introduction
The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.
Before getting started, be sure to configure a database connection in config/database.php
. For more information on configuring your database, check out the documentation.
Defining Models
To get started, let's create an Eloquent model. Models typically live in the app
directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json
file. All Eloquent models extend Illuminate\Database\Eloquent\Model
class.
The easiest way to create a model instance is using the make:model
Artisan command:
php artisan make:model User
If you would like to generate a database migration when you generate the model, you may use the --migration
or -m
option:
php artisan make:model User --migration php artisan make:model User -m
Please login to continue.