Kritim Yantra
Jul 04, 2025
Imagine you're building a blog or a product listing site. You need to:
This is called CRUD: Create, Read, Update, and Delete.
With Laravel Folio, doing CRUD operations is incredibly simple β especially for beginners.
Letβs walk through building a basic Product Manager using Folio step by step.
Make sure youβre using Laravel 12, then set up your project:
composer create-project laravel/laravel folio-crud-demo
cd folio-crud-demo
composer require laravel/folio
php artisan folio:install
This creates the resources/views/pages
folder where weβll build all our pages.
Run this command to generate the model:
php artisan make:model Product -m
Open the migration file in database/migrations/...create_products_table.php
and define columns:
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('description');
$table->decimal('price', 8, 2);
$table->timestamps();
});
Run the migration:
php artisan migrate
Create this file:
resources/views/pages/products/index.blade.php
Add this code:
<?php
use App\Models\Product;
use function Laravel\Folio\render;
render(function () {
$products = Product::all();
return view('pages.products.index', compact('products'));
});
?>
<h1>All Products</h1>
<a href="/products/create">Add Product</a>
<ul>
@foreach($products as $product)
<li>
<strong>{{ $product->title }}</strong> - ${{ $product->price }}<br>
<a href="/products/{{ $product->id }}/edit">Edit</a> |
<form action="/products/{{ $product->id }}/delete" method="POST" style="display:inline">
@csrf
<button type="submit">Delete</button>
</form>
</li>
@endforeach
</ul>
Create this file:
resources/views/pages/products/create.blade.php
<?php
use Illuminate\Http\Request;
use App\Models\Product;
use function Laravel\Folio\render;
render(function (Request $request) {
if ($request->isMethod('post')) {
$request->validate([
'title' => 'required',
'description' => 'required',
'price' => 'required|numeric',
]);
Product::create($request->only('title', 'description', 'price'));
return redirect('/products');
}
return view('pages.products.create');
});
?>
<h1>Add Product</h1>
<form method="POST">
@csrf
<input type="text" name="title" placeholder="Title"><br>
<textarea name="description" placeholder="Description"></textarea><br>
<input type="text" name="price" placeholder="Price"><br>
<button type="submit">Create</button>
</form>
In your model Product.php
, make sure you allow mass assignment:
protected $fillable = ['title', 'description', 'price'];
Create:
resources/views/pages/products/[id]/edit.blade.php
<?php
use Illuminate\Http\Request;
use App\Models\Product;
use function Laravel\Folio\render;
render(function (Request $request, $id) {
$product = Product::findOrFail($id);
if ($request->isMethod('post')) {
$request->validate([
'title' => 'required',
'description' => 'required',
'price' => 'required|numeric',
]);
$product->update($request->only('title', 'description', 'price'));
return redirect('/products');
}
return view('pages.products.edit', compact('product'));
});
?>
<h1>Edit Product</h1>
<form method="POST">
@csrf
<input type="text" name="title" value="{{ $product->title }}"><br>
<textarea name="description">{{ $product->description }}</textarea><br>
<input type="text" name="price" value="{{ $product->price }}"><br>
<button type="submit">Update</button>
</form>
Create:
resources/views/pages/products/[id]/delete.blade.php
<?php
use App\Models\Product;
use Illuminate\Http\Request;
use function Laravel\Folio\render;
render(function (Request $request, $id) {
$product = Product::findOrFail($id);
$product->delete();
return redirect('/products');
});
?>
Action | Page | Method |
---|---|---|
Create | /products/create |
POST |
Read | /products |
GET |
Update | /products/{id}/edit |
POST |
Delete | /products/{id}/delete |
POST |
With just a few Blade files and no controller or route setup, you now have a fully working CRUD app.
auth
, etc.)No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google