🛠️ Current Laravel version: Laravel 12 (released February 24, 2025)
Laravel has become one of the most popular PHP frameworks thanks to its elegant syntax, built-in tools, and active community. If you’re just starting out, this guide will take you through the first essential steps: installing Laravel, understanding routes, creating a controller, and working with models.
Step 1: Installing Laravel
1.1 System Requirements
Before installing Laravel 12, make sure your machine has:
- PHP 8.2+
- Composer (dependency manager for PHP)
- A supported database (MySQL, PostgreSQL, SQLite, SQL Server)
- PHP extensions: OpenSSL, Mbstring, PDO, Tokenizer, Ctype
Check versions:
php -v
composer -V1.2 Create a Laravel Project
Option 1 – With Composer:
composer global require laravel/installer
laravel new blog-appMove into the project and run the built-in server:
cd blog-app
php artisan serveOpen in browser:
https://127.0.0.1:8000You should see Laravel’s welcome page 🎉.
Step 2: Working with Routes
Routes tell Laravel how to respond to a request. All web routes are defined in:
📂 routes/web.php
Example: Add a new route for /hello:
use Illuminate\Support\Facades\Route;
Route::get('/hello', function () {
return "Hello, Laravel 12!";
});Visit https://127.0.0.1:8000/hello → You’ll see the message.
👉 You can also return a view:
Route::get('/about', function () {
return view('about');
});Step 3: Creating a Controller
Instead of writing logic in routes, Laravel encourages using controllers.
Generate a controller:
php artisan make:controller PostControllerThis creates 📂 app/Http/Controllers/PostController.php
Inside it, add a method:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
{
public function index()
{
return "This is the posts page.";
}
}Now link it in web.php:
use App\Http\Controllers\PostController;
Route::get('/posts', [PostController::class, 'index']);Visit https://127.0.0.1:8000/posts → Laravel loads the controller method.
Step 4: Creating a Model and Database Table
Models represent database tables. Let’s create a model for Post.
Generate a model with migration:
php artisan make:model Post -mThis creates:
- Model: app/Models/Post.php
- Migration: database/migrations/xxxx_xx_xx_create_posts_table.php
Edit the migration to add fields:
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content');
$table->timestamps();
});
}Run migration to create the table:
php artisan migrateStep 5: Using the Model in the Controller
Open PostController.php and use the model:
use App\Models\Post;
class PostController extends Controller
{
public function index()
{
// Retrieve all posts
$posts = Post::all();
return $posts;
}
public function store(Request $request)
{
$post = new Post();
$post->title = $request->title;
$post->content = $request->content;
$post->save();
return "Post created successfully!";
}
}Update routes to handle creating posts:
Route::post('/posts', [PostController::class, 'store']);Now you can send a POST request with title and content to /posts and Laravel will save it to the database 🚀.
Step 6: Next Steps
You’ve just:
✅ Installed Laravel 12
✅ Created routes
✅ Built a controller
✅ Created a model with migration
✅ Connected everything together
From here, you can:
- Learn Blade templates for views (resources/views/)
- Add validation to forms
- Use Eloquent relationships (e.g., User hasMany Posts)
- Explore API routes (routes/api.php)
Final Thoughts
Laravel 12 makes web development smoother and faster. By following these steps, you now understand the foundation: Routes → Controllers → Models → Database. From here, you’re ready to build real-world applications.