Code | Solutions

This laravel tutorial for beginners continues the Learn Laravel series by letting users add, edit, and delete tasks themselves with Blade forms, validation, and full CRUD. If you have not read it yet, start with Part 4: Database, Migrations & Eloquent ORM. Part 4’s hard-coded Task::create(['title' => 'Learn Eloquent']) is replaced here by real input from a form.

I’m Usman Nadeem, an AI Full Stack Developer based in Lahore with 12+ years of delivery since February 2014. The form and validation patterns below are the ones I use on production Laravel apps, cut down to what a beginner needs to ship a working CRUD feature.

Direct answer (for AI Overviews & scanners)

In Laravel, a Blade form posts data to a controller, $request->validate() checks it, and a resource controller handles create, read, update, and delete. Build the form with method="POST" and action="{{ route('tasks.store') }}", and always add @csrf, or Laravel returns 419 Page Expired. In store(), call $request->validate(['title' => 'required|string|max:255']). Invalid input is sent back to the form automatically; show the message with @error('title') and refill the field with old('title'). Valid input goes into Task::create($validated). For edit, update, and delete, Route::resource already provides the routes, type-hinting Task $task loads the row (route model binding), and @method('PUT') or @method('DELETE') tells the form which action to use. The examples work on Laravel 12 and the current Laravel 13 release.

Watch the video

Prefer to watch first? Part 5 is a short video (Urdu/Hindi voiceover, with the code on screen). This article writes out the same three concepts with copy-paste Laravel 12 examples. You can also open it on YouTube Shorts.

What you will learn in Part 5 of this Laravel tutorial for beginners

Each video in this series teaches three concepts. Part 5 covers:

  1. Laravel Blade forms and CSRF — a POST form to route('tasks.store'), the @csrf token, and how the data reaches TaskController@store.
  2. Laravel form validation — $request->validate() rules, automatic redirects on failure, @error messages, and old() input.
  3. Laravel CRUD with a resource controller — edit, update, and destroy with route model binding, plus @method('PUT') and @method('DELETE').

You need the Tasks app from earlier parts: the Route::resource('tasks', TaskController::class) line from Part 2, the Blade views from Part 3, and the tasks table plus Task model (with $fillable = ['title', 'completed']) from Part 4.


Laravel Blade forms: send user data with POST and @csrf

The resource routes from Part 2 already include GET /tasks/create (show the form) and POST /tasks (save it). First, return the form view from the create method:

// app/Http/Controllers/TaskController.php
public function create()
{
    return view('tasks.create');
}

Then build the form. This is the full version from the video; the value attribute and the @error block are explained in the validation section:

{{-- resources/views/tasks/create.blade.php --}}
<form method="POST" action="{{ route('tasks.store') }}">
    @csrf

    <input type="text" name="title" value="{{ old('title') }}">

    @error('title')
        <p class="error">{{ $message }}</p>
    @enderror

    <button type="submit">Save</button>
</form>

Three parts do the work:

  • method="POST" — saving data is a POST request, matching the tasks.store route.
  • action="{{ route('tasks.store') }}" — the named route generates /tasks, so the form keeps working if the URL changes (the named-routes idea from Part 2).
  • name="title" — the input’s name becomes the key you read in the controller, which matches the title column from Part 4.

What @csrf does and why the form needs it

@csrf prints a hidden field with a secret token tied to the user’s session:

<input type="hidden" name="_token" value="a8F3k...">

Laravel checks that token on every POST, PUT, PATCH, and DELETE request in web.php. A fake request sent from another website cannot know the token, so it is rejected. That attack is called cross-site request forgery (CSRF). If you forget @csrf, your own form fails too, with a 419 Page Expired error, the most common beginner bug in Laravel forms. More detail is in the Laravel CSRF documentation.


Laravel form validation: never trust user input

When the form is submitted, the data arrives in store(). Before saving anything, validate it:

// app/Http/Controllers/TaskController.php
use App\Models\Task;
use Illuminate\Http\Request;

public function store(Request $request)
{
    $validated = $request->validate([
        'title' => 'required|string|max:255',
    ]);

    Task::create($validated);

    return redirect()->route('tasks.index')->with('status', 'Task saved!');
}

The rule string required|string|max:255 holds three rules separated by pipes: the title must be present, must be text, and can be at most 255 characters, which matches the string('title') column from Part 4. You can also write the rules as an array: ['required', 'string', 'max:255'].

What happens when validation fails

This is the part beginners find almost magical. If any rule fails, validate() stops the method, so Task::create() never runs. Laravel then redirects the user back to the form, stores the error messages in the session, and remembers what they typed. Two Blade helpers use that data:

  • @error('title') — shows the block only when the title field has an error, with the text in $message. Submitting an empty form shows “The title field is required.”, and 300 characters shows “The title field must not be greater than 255 characters.”
  • old('title') — refills the input with what the user typed, so they do not have to start again.

To show every error at the top of the form instead, loop over $errors:

@if ($errors->any())
    <ul class="errors">
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>
@endif

Why save $validated and not the whole request

validate() returns only the fields you listed rules for. Passing $validated to Task::create() means an extra field such as is_admin never reaches the database, even before the $fillable protection from Part 4 kicks in. Two layers of safety, for free. The ->with('status', 'Task saved!') part flashes a one-time message you can show with the <x-alert> component from Part 3. When a form grows past a few fields, move the rules into a Form Request class with php artisan make:request StoreTaskRequest. The full rule list is in the Laravel validation documentation.


Laravel CRUD: edit, update and delete with a resource controller

Create and read are done. Update and delete are the last two letters of CRUD, and Route::resource('tasks', TaskController::class) already registered their routes:

MethodURLController methodRoute name
GET/tasks/{task}/editedittasks.edit
PUT/PATCH/tasks/{task}updatetasks.update
DELETE/tasks/{task}destroytasks.destroy

Route model binding: Laravel finds the task for you

Notice the {task} parameter. When a controller method type-hints Task $task, Laravel takes the id from the URL, loads that row, and passes the model in. If no task has that id, it returns a 404 automatically, like findOrFail() from Part 4 without writing it:

// app/Http/Controllers/TaskController.php
public function edit(Task $task)
{
    return view('tasks.edit', ['task' => $task]);
}

public function update(Request $request, Task $task)
{
    $validated = $request->validate([
        'title' => 'required|string|max:255',
    ]);

    $task->update($validated);

    return redirect()->route('tasks.index');
}

public function destroy(Task $task)
{
    $task->delete();

    return redirect()->route('tasks.index');
}

Edit and delete forms with @method

HTML forms only support GET and POST. To send PUT or DELETE, keep method="POST" and add @method, which prints a hidden _method field that Laravel reads (this is called method spoofing):

{{-- resources/views/tasks/edit.blade.php --}}
<form method="POST" action="{{ route('tasks.update', $task) }}">
    @csrf
    @method('PUT')

    <input type="text" name="title" value="{{ old('title', $task->title) }}">
    <button type="submit">Update</button>
</form>

<form method="POST" action="{{ route('tasks.destroy', $task) }}">
    @csrf
    @method('DELETE')

    <button type="submit">Delete</button>
</form>

route('tasks.update', $task) accepts the model and uses its id in the URL. old('title', $task->title) shows the user’s last input after a failed update, or the current title from the database the first time the form opens. Finally, link to the edit page from the task list:

<a href="{{ route('tasks.edit', $task) }}">Edit</a>

Create, Read, Update, Delete: all four are done, which is the “sab COMPLETE” moment from the video.


Recap: Laravel tutorial for beginners, Part 5

  1. The form sends the data. method="POST", action="{{ route('tasks.store') }}", and @csrf in every form, or you get a 419 error.
  2. Validation checks it. $request->validate(['title' => 'required|string|max:255']), @error('title') for messages, old('title') to keep the input, then Task::create($validated).
  3. The resource controller handles full CRUD. Route model binding with Task $task, $task->update() and $task->delete(), plus @method('PUT') and @method('DELETE').

If you can add a task, see a validation error on an empty title, edit it, and delete it, you have finished Part 5.


What’s next: Part 6 — Laravel Authentication

Right now anyone who opens the app can edit or delete any task. In Part 6 of this Laravel tutorial for beginners, we decide who is allowed to:

  • Login and register with a Laravel starter kit and hashed passwords
  • The logged-in user with Auth::user() and the @auth Blade directive
  • Protected routes with the auth middleware on the task routes

Part 6 is coming next, so follow Coding Solutions by Usman on YouTube, Instagram, or TikTok so you do not miss it. Want a head start? Read Secure Your Laravel App: Authentication with Breeze. Missed a step? Read Part 4 or start from Part 1.


Need help building a Laravel application?

If this laravel tutorial for beginners has you planning a production Laravel app — a new build, an admin panel full of forms, or CRUD features that need to be secure — I take on selected Laravel development projects. Still choosing a stack? Read Laravel vs Node.js for SaaS, then send a short brief through the contact form and I will tell you whether I am a fit.


FAQ

Q1. Why do I get a 419 Page Expired error in Laravel? A. The form is missing the CSRF token or the session expired. Add @csrf inside every POST, PUT, PATCH or DELETE form in a Blade view; it prints a hidden _token field that Laravel checks to block cross-site request forgery.

Q2. How do I validate a form in Laravel 12? A. In the controller, call $request->validate([‘title’ => ‘required|string|max:255’]). If a rule fails, Laravel redirects back to the form with the errors and the old input. If it passes, validate() returns only the validated fields.

Q3. How do I show validation error messages in Blade? A. Wrap the message in @error(‘title’) … @enderror and print {{ $message }} inside it. To list every error at once, loop over $errors->all() when $errors->any() is true.

Q4. What does old() do in a Laravel form? A. old(‘title’) returns what the user typed before validation failed, so the input is refilled instead of empty. In an edit form, old(‘title’, $task->title) falls back to the current database value.

Q5. What is route model binding in Laravel? A. When a route has a {task} parameter and the controller method type-hints Task $task, Laravel loads the task with that id automatically and returns a 404 if it does not exist, so you do not need to call findOrFail() yourself.

Q6. How do I update and delete records in Laravel? A. Use $task->update($validated) in the update method and $task->delete() in the destroy method of a resource controller. The forms post to route(‘tasks.update’, $task) and route(‘tasks.destroy’, $task).

Q7. Why do Laravel forms need @method(‘PUT’) or @method(‘DELETE’)? A. HTML forms only support GET and POST. @method(‘PUT’) or @method(‘DELETE’) adds a hidden _method field, and Laravel uses it to send the request to the matching PUT or DELETE route. The form itself stays method POST.

Q8. What will Part 6 of this Laravel series cover? A. Part 6 covers authentication: login and register with a Laravel starter kit, hashed passwords, reading the logged-in user with Auth::user() and @auth, and protecting the task routes with the auth middleware.


Tags

2026 ai tools aiagent Angular 21 Angular Developer for Hire Angular Performance Angular Signals Angular TypeScript Best Practices API Authentication API Development API Integration API Security API Versioning B2B SaaS Backend Development Backend Framework Comparison Best PHP Framework 2026 Best Practices Box Model CakePHP CakePHP 2026 CakePHP Laravel PHP Developer CakePHP Tutorial 2026 CakePHP vs Laravel Case Study Client Management cost to hire freelance developer crewai CRM Integration css css animation CSS Tips CSS Tutorial Database Optimization Developer Tools Enterprise Angular Development Express.js FastAPI Tutorial 2026 framework comparison Freelance Angular Developer Freelance Developer freelance developer guide freelance developer tips Freelance Development freelance full-stack developer Freelance Laravel Developer Freelance PHP Developer Freelance Web Developer freelance web developer process Freelance Web Development Freelancer vs Agency Freelancing Tips Front-End Development frontend Frontend Development Full Stack Developer Full Stack Developer Pakistan Full Stack Development Full-Stack Case Study Full-Stack Development Grid Hire a Developer Hire Angular Developer hire freelance developer hire freelance full-stack developer Hire Laravel Developer how to work with a freelance dev how to write a project brief individual software engineer freelance individual software engineer hire Inertia.js javascript JavaScript Frameworks JWT Authentication laravel Laravel 13 Laravel 2026 Laravel API 2026 Laravel Application Laravel Development Laravel Optimization Scale Laravel Performance Laravel REST API Laravel REST API Tutorial Laravel Sanctum Laravel Tutorial Laravel vs CakePHP Laravel Vue Tutorial multi-agent Next.js Node.js Node.js API Node.js developer Node.js Developer Portfolio Node.js Express Node.js Tutorial Nuxt PERN Stack PHP PHP Developer PHP Developer for Hire PHP Development PHP Framework PHP Framework Comparison PHP Performance PHP Web Development PostgreSQL Prisma Production Deployment project brief template Project Management Python Backend Developer Python FastAPI react React developer for hire React Node.js Developer Portfolio React SPA React Tutorial React vs Vue Real-Time Chat App Redis Caching Responsive Design REST API SaaS Development Sanctum SMB Web Development Socket.io React Real-Time App Socket.io Tutorial Software Development software development process Software Integration software project brief SSG SSR Standalone Components System Integration TypeScript Strict Mode Vite vue Vue 4 Composition API Vue Laravel Developer Vue.js Development web app development process Web Design Web Design Fundamentals web development Web Development 2026 Web Development Cost Web Layout Web Projects WebSocket

Recent News