← Back to Modules

Interactive Demo

🎯 Interactive Demo

Eloquent Model CRUD Operations

Watch how Eloquent handles Create, Read, Update, and Delete operations with automatic query generation.

Creating Models

Using new and save()

$user = new User();
$user->name = 'Demo User';
$user->save();

Queries executed: 1

Using create()

User::create([
    'name' => 'Mass Assigned User',
    'email' => '...',
]);

Queries executed: 2

📝 Reading & Updating

User::find()

$user = User::find(12);
// Returns: Updated Demo User

Queries executed: 5

Modify and save()

$user->name = 'Updated Demo User';
$user->save();  // Updates only changed fields

Queries executed: 4

🔍 Query Builder Methods

User::latest()->take(5)->get()

// Returns 5 most recent users
User::latest()->take(5)->get();

Queries executed: 6

Results:
Mass Assigned User - mass4843@example.com
Updated Demo User - demo2452@example.com
Vicente Wisozk Sr. - jwhite@example.com
Olen Mayer - ohoeger@example.org
Shakira Koepp - shany07@example.org

🎓 Key Concepts

Active Record Pattern

Each model instance represents a database row with built-in save/delete methods.

Mass Assignment

Use $fillable to protect against bulk assignment vulnerabilities.

Automatic Timestamps

Laravel automatically manages created_at and updated_at.