Introduction
In this tutorial, you’ll learn how to build a simple blog-like CRUD application using Laravel 12. We'll create posts with titles and content, list them, edit them, and delete them. This guide assumes you know basic terminal usage and have a development environment set up.
Requirements
-
PHP 8.1 or newer
-
Composer
-
MySQL or MariaDB (or any supported database)
-
Optional: Node.js & NPM (for frontend assets / compiling CSS/JS)
Step 1 — Create a new Laravel project
Run:
Start the development server:
Visit http://localhost:8000 to confirm Laravel is running.
Step 2 — Project structure (quick guide)
-
app/— Models, Controllers, core logic -
routes/—web.php(web routes),api.php(API routes) -
resources/views/— Blade templates (HTML views) -
database/migrations/— Migrations (DB schema)
Step 3 — Database Setup
Edit .env:
Step 4 — Create Post model + migration
Generate a model with migration:
Open the migration file in database/migrations/ (it will be timestamped) and edit the up() method:
Run migrations:
Step 5 — Add mass assignment protection to the model
Open app/Models/Post.php and add $fillable So you can use Post::create() safely:
Step 6 — Generate Controller (resource)
Create a resource controller to handle CRUD:
This command creates app/Http/Controllers/PostController.php with boilerplate methods (index, create, store, show, edit, update, destroy).
Step 7 — Implement controller methods
Replace the controller methods with the following (concise implementation):
Step 8 — Add resource routes
Open routes/web.php and add:
php artisan route:list will now show all RESTful routes for posts.
Step 9 — Create Blade views (basic)
Create a resources/views/posts folder and add the following minimal templates.
resources/views/layouts/app.blade.php (master layout)
resources/views/posts/index.blade.php
resources/views/posts/create.blade.php and edit.blade.php
You can use the same form partial for create/edit.
resources/views/posts/create.blade.php:
resources/views/posts/edit.blade.php:
resources/views/posts/show.blade.php
Step 10 — Test the app
-
Visit
/posts— should show list (initially empty) -
Create a post via
/posts/create -
Edit and delete posts via the UI
If you encounter validation errors, the forms will display them (we have included server-side validation in the controller).
Step 11: Next Steps
-
Learn Laravel Policies & Gates
-
Protect Routes with Middleware
-
Use Blade Directives for Authorization
-
Customize User Access Based on Roles

