Performing Basic CRUD Operations in Laravel with Eloquent
Master database operations with our guide to CRUD in Laravel. Learn how to save, fetch, update, and delete records using the powerful Eloquent ORM.
Previously in this course, we covered working with Eloquent models, where we learned how to define a model and link it to a database table. In this lesson, we are moving from simply defining models to actually manipulating the data inside them: performing basic CRUD operations.
CRUD stands for Create, Read, Update, and Delete—the four fundamental actions required for any data-driven application. In Laravel, Eloquent makes these operations incredibly intuitive by allowing us to interact with database rows as if they were standard PHP objects.
Creating and Saving Records
To create a new record, you instantiate your model as a new object, set its attributes, and call the save() method.
PHPuse App\Models\Task; $task = new Task; $task->title = 'Learn Laravel Eloquent'; $task->description = 'Master the basics of CRUD operations.'; $task->save();
When you call save(), Laravel translates this object into an INSERT SQL statement and executes it. After saving, the model instance will automatically have its primary key (the id column) populated, which is useful if you need to redirect the user to that specific record immediately.
Reading Records
Eloquent provides a fluent interface for fetching data. You’ve already seen basic retrieval, but it’s helpful to understand the variations:
- Fetch all:
Task::all()returns a collection of all records. - Find by ID:
Task::find(1)returns a single model instance ornullif not found. - Find or Fail:
Task::findOrFail(1)returns the model or throws a 404 exception, which is perfect for controller actions where you don't want to handlenullmanually. - Filtering:
Task::where('completed', false)->get()allows you to chain conditions before executing the query.
Updating Attributes
Updating a record follows a similar pattern to creating one. First, retrieve the instance, change the desired attributes, and call save() again.
PHP$task = Task::find(1); $task->completed = true; $task->save();
Laravel is smart enough to know that because the model already exists in the database, calling save() should perform an UPDATE statement instead of an INSERT.
Deleting a Record
Once you have a model instance, deleting it is as simple as calling the delete() method.
PHP$task = Task::find(1); $task->delete();
You can also delete a record directly by its primary key without retrieving the object first: Task::destroy(1);. This is an efficient shortcut when you only have the ID available.
Hands-on Exercise
To practice these operations, open your project and use php artisan tinker in your terminal. Tinker is an interactive shell that lets you run Laravel code in real-time.
- Create a new Task:
$t = new App\Models\Task; $t->title = 'Test'; $t->save(); - Retrieve it:
$t = App\Models\Task::latest()->first(); - Update the title:
$t->title = 'Updated Title'; $t->save(); - Delete it:
$t->delete();
Observe the output in your terminal after each command. You'll see the SQL queries being executed behind the scenes.
Common Pitfalls
- Forgetting to save: A common mistake is updating an attribute (e.g.,
$task->title = 'New') but forgetting to call->save(). Without that final method call, the change never reaches the database. - Mass Assignment: While
new Task(['title' => '...'])is convenient, it requires you to configure the$fillableproperty on your model to protect against security vulnerabilities. We will cover this in detail in a later lesson on preventing mass assignment. - Using
all()on large tables: If your tasks table grows to thousands of records,Task::all()will consume a massive amount of memory. Always prefer pagination for lists.
Recap
Eloquent provides a clean, object-oriented syntax for your database operations. By leveraging save(), find(), and delete(), you can manage your Task Manager's data with minimal boilerplate. Remember that these methods are the building blocks for the more complex logic we will implement in our controllers.
Up next: We will learn about seeding the database to populate our application with dummy data for testing.
Work with me

FilamentPHP Admin Panel & Dashboard Development
A powerful admin panel for your Laravel app — built with FilamentPHP so you can manage everything without touching the database.

Laravel REST API Development
Clean, secure, well-documented Laravel REST APIs — the backend engine for your app, mobile client, or SaaS. Built by an API specialist.