What is Eloquent?
Eloquent is Laravel's Object-Relational Mapping (ORM) system. It allows you to interact with your database using PHP classes and objects.
Key Features:
- Simplifies database interactions
- Defines database tables as PHP classes (models)
- Supports CRUD operations (Create, Read, Update, Delete)
- Defines relationships between tables
Basic Example:
Let's say we have a jobs
table in your database. With Eloquent, you can create a Job
model to interact with that table:
// app/Models/Job.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Job extends Model
{
protected $table = 'job_listings';
protected $fillable = ['title' , 'salary'];
}
That's it! We can now use the Job
model to perform database operations, like creating a new job.
Eloquent provides a simple and elegant way to work with your database in Laravel.
Top comments (0)