Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 31 of the Laravel Fundamentals: From Zero to Your First App course
LaravelJune 25, 20263 min read

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.

LaravelCRUDEloquentMVCPHPbackend

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:

  1. A GET route to display the "Edit" form.
  2. A PUT or PATCH route 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.

HTML
style="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.

PHP
public 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

  1. Open your TasksController and ensure you have an edit(Task $task) method that returns a view.
  2. Create the edit.blade.php file using the code block above as a template.
  3. 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>.
  4. 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 a POST request, which usually results in a 405 Method Not Allowed error because your route is defined as PUT or PATCH.
  • Mass Assignment Errors: If you try to update a field like user_id that isn't in your $fillable array, 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.

Previous lessonIntroduction to Route Model BindingNext lesson Deleting Records
Back to Blog

Similar Posts

LaravelJune 25, 20263 min read

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.

Read more
LaravelJune 25, 20263 min read

Working with Eloquent Models in Laravel: A Beginner's Guide

Learn how to use Eloquent, Laravel's powerful ORM, to interact with database tables as clean, object-oriented models for your Task Manager application.

Part of the course

Laravel Fundamentals: From Zero to Your First App

beginner · Lesson 31 of 52

  1. 1

    Setting Up the Local Development Environment

    4 min
  2. 2

    Installing Laravel and Exploring Directory Structure

    3 min
  3. 3

    Understanding the .env File and Configuration

    3 min
Read more
LaravelJune 25, 20264 min read

Querying Related Data: Mastering Eager Loading in Laravel

Stop the N+1 query problem in its tracks. Learn how to use eager loading in Laravel to keep your application fast and efficient as your data grows.

Read more
  • 4

    The Laravel Application Lifecycle

    4 min
  • 5

    Initializing the Task Manager Project

    3 min
  • 6

    Defining Basic Web Routes

    4 min
  • 7

    Using Route Parameters

    3 min
  • 8

    Creating Your First Controller

    3 min
  • 9

    Returning Responses and Redirects

    3 min
  • 10

    Task Manager: Implementing the Task List Route

    3 min
  • 11

    Introduction to Blade Templating

    3 min
  • 12

    Using Blade Layouts and Sections

    3 min
  • 13

    Implementing Blade Partials

    4 min
  • 14

    Mastering Blade Directives for Loops and Conditionals

    3 min
  • 15

    Task Manager: Building the User Interface

    3 min
  • 16

    Understanding Database Migrations

    3 min
  • 17

    Working with Eloquent Models

    3 min
  • 18

    Performing Basic CRUD Operations

    3 min
  • 19

    Seeding the Database

    3 min
  • 20

    Task Manager: Displaying Real Database Records

    3 min
  • 21

    Capturing User Input from Forms

    4 min
  • 22

    Introduction to Laravel Validation

    3 min
  • 23

    Customizing Validation Error Messages

    3 min
  • 24

    Using Form Requests for Validation

    3 min
  • 25

    Introduction to Authentication

    4 min
  • 26

    Protecting Routes with Middleware

    3 min
  • 27

    Understanding CSRF Protection

    3 min
  • 28

    Preventing Mass Assignment

    3 min
  • 29

    Task Manager: Securing the Application

    3 min
  • 30

    Introduction to Route Model Binding

    3 min
  • 31

    Updating Existing Records

    3 min
  • 32

    Deleting Records

    3 min
  • 33

    Using Named Routes

    3 min
  • 34

    Task Manager: Completing CRUD Functionality

    3 min
  • 35

    Introduction to Database Relationships

    3 min
  • 36

    Querying Related Data

    4 min
  • 37

    Handling File Uploads

    Coming soon
  • 38

    Using Flash Messages for User Feedback

    Coming soon
  • 39

    Task Manager: Adding Status and Priorities

    Coming soon
  • 40

    Introduction to Artisan Commands

    Coming soon
  • 41

    Debugging with Laravel Tinker

    Coming soon
  • 42

    Understanding Service Providers

    Coming soon
  • 43

    Using View Composers

    Coming soon
  • 44

    Task Manager: Refactoring for Clean Code

    Coming soon
  • 45

    Introduction to Testing

    Coming soon
  • 46

    Testing Forms and Validation

    Coming soon
  • 47

    Using Database Transactions

    Coming soon
  • 48

    Handling Global Exceptions

    Coming soon
  • 49

    Preparing for Production

    Coming soon
  • 50

    Environment Security Best Practices

    Coming soon
  • 51

    Managing Assets in Production

    Coming soon
  • 52

    Task Manager: Deployment Preparation

    Coming soon
  • View full course