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:
- Laravel Blade forms and CSRF — a POST form to
route('tasks.store'), the@csrftoken, and how the data reachesTaskController@store. - Laravel form validation —
$request->validate()rules, automatic redirects on failure,@errormessages, andold()input. - Laravel CRUD with a resource controller —
edit,update, anddestroywith 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 thetasks.storeroute.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 thetitlecolumn 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 thetitlefield 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>
@endifWhy 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:
| Method | URL | Controller method | Route name |
|---|---|---|---|
| GET | /tasks/{task}/edit | edit | tasks.edit |
| PUT/PATCH | /tasks/{task} | update | tasks.update |
| DELETE | /tasks/{task} | destroy | tasks.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
- The form sends the data.
method="POST",action="{{ route('tasks.store') }}", and@csrfin every form, or you get a 419 error. - Validation checks it.
$request->validate(['title' => 'required|string|max:255']),@error('title')for messages,old('title')to keep the input, thenTask::create($validated). - 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@authBlade directive - Protected routes with the
authmiddleware 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.
