Updating Existing Records: A Laravel CRUD Guide
Master updating existing records in Laravel. Learn how to bind Eloquent models to edit forms, handle PUT requests, and persist changes to your database.
Previously in this course, we covered Introduction to Route Model Binding in Laravel, which allows us to automatically fetch database records based on URL parameters. In this lesson, we will use that skill to implement the "Update" functionality for our Task Manager.
Updating records is the third step in the classic CRUD (Create, Read, Update, Delete) cycle. While creating records involves sending new data to the server, updating requires a two-step dance: displaying an existing record in a form, then sending those modified values back to the server to persist changes.
The Edit Workflow
To update an existing record, you generally need two routes:
- A
GETroute to display the "Edit" form. - A
PUTorPATCHroute to process the form submission and save the changes.
Step 1: Creating the Edit Form
In your tasks/edit.blade.php view, you need to populate your form inputs with the current values of the task. Because we are using Route Model Binding, our controller will pass a $task object to the view.
HTMLstyle="color:#808080"><style="color:#4EC9B0">form action="/tasks/{{ $task->id }}" method="POST"> @csrf @method('PUT') style="color:#808080"><style="color:#4EC9B0">input type="text" name="title" value="{{ old('title', $task->title) }}"> style="color:#808080"><style="color:#4EC9B0">textarea name="description">{{ old('description', $task->description) }}style="color:#808080"></style="color:#4EC9B0">textarea> style="color:#808080"><style="color:#4EC9B0">button type="submit">Update Taskstyle="color:#808080"></style="color:#4EC9B0">button> style="color:#808080"></style="color:#4EC9B0">form>
Notice the @method('PUT') directive. Since standard HTML forms only support GET and POST, Laravel uses this hidden field to simulate a PUT request, which is the RESTful standard for updates.
Step 2: Persisting the Update
In your TasksController, you will handle the submission. You should follow the principles we discussed in Performing Basic CRUD Operations in Laravel with Eloquent and Preventing Mass Assignment in Laravel.
PHPpublic function update(Request $request, Task $task) { #6A9955">// 1. Validate the incoming data $validated = $request->validate([ 'title' => 'required|max:255', 'description' => 'nullable', ]); #6A9955">// 2. Update the model instance $task->update($validated); #6A9955">// 3. Redirect the user return redirect('/tasks')->with('success', 'Task updated successfully!'); }
The $task->update() method is a powerful Eloquent feature. It automatically filters the input array against your model's $fillable property and saves only the permitted fields to the database.
Hands-on Exercise
- Open your
TasksControllerand ensure you have anedit(Task $task)method that returns a view. - Create the
edit.blade.phpfile using the code block above as a template. - Add a link in your task list view (from Task Manager: Displaying Real Database Records) that points to the edit route:
<a href="/tasks/{{ $task->id }}/edit">Edit</a>. - Submit the form and verify that the database table reflects your changes.
Common Pitfalls
- Forgetting
@method('PUT'): If you omit this, Laravel will treat the form as aPOSTrequest, which usually results in a405 Method Not Allowederror because your route is defined asPUTorPATCH. - Mass Assignment Errors: If you try to update a field like
user_idthat isn't in your$fillablearray, Laravel will silently ignore it for security reasons. Always double-check your model's fillable configuration if data isn't saving. - Validation Overlap: Don't forget that updates often require different validation rules than creation (e.g., unique constraints that need to ignore the current record). Use the rule builder's
ignore()method if you encounter this.
Recap
Updating records relies on retrieving the correct model instance, injecting it into a view pre-populated with current data, and using the update() method to persist modifications. By leveraging Eloquent's mass-assignment protection and route model binding, you keep your code clean and secure.
Up next: Deleting Records — how to remove data safely and clean up your database.
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.