Laravel 12 is the latest and most powerful version of the popular PHP framework that simplifies web development with its elegant syntax and built-in features. In this tutorial, we'll walk through how to build a complete CRUD (Create, Read, Update, Delete) application using Laravel 12 step-by-step.
Whether you're a beginner or want to refresh your Laravel basics, this guide is designed to help you master the core concepts of Laravel 12 development.
🧰 What You'll Learn
- Installing Laravel 12
- Database configuration
- Creating Model, Migration, and Controller
- Building Blade views
- Writing routes for CRUD operations
- Validating form input
- Testing the application
🖥️ Step 1: Install Laravel 12
First, make sure you have Composer installed.
Navigate into the project:
Run the built-in Laravel server:
⚙️ Step 2: Setup the Database
Open .env
file and configure your database:
Then, create the database in MySQL (e.g., via phpMyAdmin or command line).
🧱 Step 3: Create Model, Migration & Controller
Let’s say we're building a Post manager.
Run this artisan command:
This will create:
- Model:
app/Models/Post.php
- Migration:
database/migrations/xxxx_create_posts_table.php
- Controller:
app/Http/Controllers/PostController.php
Edit the migration file to add columns:
Then migrate:
✍️ Step 4: Define Routes
Open routes/web.php
and add:
This creates all necessary CRUD routes.
🧠 Step 5: Controller Logic
Open PostController.php
and define logic:
💾 Step 6: Setup Blade Views
1. resources/views/posts/layout.blade.php
2. resources/views/posts/index.blade.php
3. resources/views/posts/create.blade.php
4. resources/views/posts/edit.blade.php
Same as create, but pre-filled:
5. resources/views/posts/show.blade.php
🧪 Step 7: Run and Test
Make sure your development server is running:
http://127.0.0.1:8000/posts
You should be able to:
- Create a new post
- See the list of posts
- View a single post
- Edit a post
- Delete a post