Writing the expanded article now.

Image: Art Institute of Chicago
By the end of this guide you will have a working Laravel 12 application that reads posts from a database and displays them in a browser. You will understand the Model-View-Controller architecture, know your way around the directory structure, and have built a real feature from scratch – a posts listing page backed by a database table you created yourself. Whether you are coming from vanilla PHP or switching from another framework, this Laravel 12 tutorial for beginners covers everything you need to start productively.
Prerequisites

Image: Art Institute of Chicago
Before you install anything, confirm you have the following in place.
Tools required:
– PHP 8.2 or higher (check with php -v)
– Composer (check with composer -V)
– Node.js and NPM (check with node -v && npm -v)
– A terminal you are comfortable using
– A code editor – if you are new to VS Code, our Tutorial: Get started with Visual Studio Code is a good starting point
Prior knowledge expected:
– Basic PHP syntax (variables, functions, arrays)
– Familiarity with HTML
– Confidence running commands in a terminal
If you have only just started with PHP, read our guide on how to run a PHP file using XAMPP before continuing here. Skipping prerequisites is the single most common reason beginners get stuck in the first ten minutes.
Why Laravel 12
Laravel gives a solo developer – or a small team – the capacity to build at a pace that would otherwise require a much larger engineering effort. Every Laravel project ships with authentication and authorisation, the Eloquent ORM for database interaction, routing and middleware, REST API scaffolding, a background job queue, task scheduling, caching, and database migrations – all without a single third-party package.
Laravel 12, released in early 2026, continues this trajectory with updated starter kits, improved routing, and enhanced testing support. Laravel follows Semantic Versioning: major releases ship annually around Q1, with minor and patch releases appearing frequently throughout the year. The current stable line is v12, with Laravel 13 already in active development. This predictable cadence matters for project planning – you know exactly when upgrades are coming and how much runway you have on your current version.
Laravel 12 Step-by-Step: From Zero to a Working Posts Page
This walkthrough builds a single feature end to end – a page that lists posts stored in a database. Each step adds one layer. Follow the steps in order; each one depends on the last.
Step 1: Verify your PHP version
php -v
You should see PHP 8.2.x or higher. If you see an older version, upgrade before continuing – Laravel 12 will refuse to install on anything below PHP 8.2, and the resulting error message is not always clear about why.
Step 2: Create a new Laravel project
composer create-project laravel/laravel my-project
Composer downloads the Laravel framework and all its dependencies into a folder called my-project. This takes a minute or two. Do not interrupt it midway – partial installs leave the project in a broken state that is easier to delete and restart than to repair.
You should see a Application key set successfully. message near the end of the output. That confirms the project was created correctly.
Step 3: Move into your project directory
cd my-project
Every subsequent command in this guide runs from inside this directory.
Common mistake: Forgetting this step. If your terminal returns
Could not open input file: artisan, you are outside your project folder. Runcd my-projectfirst, then retry.
Step 4: Configure your database in .env
Open the .env file in the root of your project. This file holds environment-specific configuration – database credentials, app name, mail settings – that never gets committed to version control.
Find these lines and update them to match your local database:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_project
DB_USERNAME=root
DB_PASSWORD=
Create the database first in MySQL (or your preferred database client) before running any migrations. If you are using SQLite for a quick local setup, change DB_CONNECTION=mysql to DB_CONNECTION=sqlite and remove the other DB_* lines – Laravel will create a database/database.sqlite file automatically.
Common mistake: Leaving
DB_DATABASEpointing at the defaultlaraveldatabase name without creating that database first. You will get aSQLSTATE[HY000] [1049] Unknown databaseerror when you run migrations. Create the database in MySQL, or switch to SQLite, before continuing.
Step 5: Start the development server
php artisan serve
Open your browser and navigate to http://127.0.0.1:8000. You should see the Laravel welcome page – a clean landing page with the Laravel logo and some links. This confirms the framework is installed and running.
If you see a blank page or a connection error: Check that no other process is already using port 8000. You can specify an alternative port with
php artisan serve --port=8080.
Step 6: Install front-end dependencies
npm install && npm run dev
This compiles your CSS and JavaScript assets using Vite, Laravel’s default front-end bundler. You need Node.js and NPM for this step. Your styles will not load correctly once you move beyond the welcome page if you skip it.
If you see
vite: command not found: NPM did not install correctly. Runnpm installagain from inside the project directory, then retrynpm run dev.
Step 7: Create a migration for your posts table
A migration is a version-controlled blueprint for a database table. Create one now:
php artisan make:migration create_posts_table
Laravel creates a file inside database/migrations/ with a timestamp in its name. Open it and update the up() method to define your table:
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
Save the file, then run the migration:
php artisan migrate
You should see output like Running migrations... DONE. Your posts table now exists in the database.
Common mistake: Editing the migration file after running it and expecting the database to update. Once a migration has run, changes to it have no effect. Instead, create a new migration to alter the table, or roll back with
php artisan migrate:rollbackand re-run.
Step 8: Create an Eloquent model
An Eloquent model is a PHP class that maps to your database table and lets you query and modify data without writing raw SQL.
php artisan make:model Post
Laravel creates app/Models/Post.php. For now, the default contents are all you need – Eloquent infers the table name (posts) from the class name automatically.
Step 9: Seed some test data
Open database/seeders/DatabaseSeeder.php and add a few sample posts:
use App\Models\Post;
public function run(): void
{
Post::create(['title' => 'First post', 'body' => 'Hello from Laravel 12.']);
Post::create(['title' => 'Second post', 'body' => 'This is the second post.']);
}
Run the seeder:
php artisan db:seed
You should see Database seeding completed successfully. Your posts table now has two rows.
Step 10: Create a controller
A controller receives an HTTP request, fetches data, and hands it to a view. Generate one:
php artisan make:controller PostController
Open app/Http/Controllers/PostController.php and add an index method:
use App\Models\Post;
public function index()
{
$posts = Post::all();
return view('posts.index', compact('posts'));
}
The controller queries all posts and passes them to a Blade view.
Common mistake: Writing database queries directly inside a Blade view. This bypasses MVC entirely and makes debugging extremely difficult. Data retrieval belongs in the controller.
Step 11: Register a route
Open routes/web.php and add:
use App\Http\Controllers\PostController;
Route::get('/posts', [PostController::class, 'index']);
This maps GET requests to /posts to the controller method you just wrote.
Step 12: Create the Blade view
Create a folder resources/views/posts/ and inside it a file named index.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Posts</title>
</head>
<body>
<h1>Posts</h1>
@forelse ($posts as $post)
<article>
<h2>{{ $post->title }}</h2>
<p>{{ $post->body }}</p>
</article>
@empty
<p>No posts found.</p>
@endforelse
</body>
</html>
Now visit http://127.0.0.1:8000/posts in your browser. You should see both posts listed on the page – “First post” and “Second post” – rendered as HTML.
That is your first end-to-end Laravel feature: a database table, a model, a controller, a route, and a view, each doing exactly one job.
Nuances Most Beginners Miss in Laravel 12
Eloquent relationships are the most commonly skipped concept. A User model can declare hasMany(Post::class), and from that point you can write $user->posts anywhere in your application. Eloquent handles the SQL automatically, including eager loading to prevent the N+1 query problem – where fetching 100 users fires 101 database queries instead of 2.
Middleware sits between an incoming HTTP request and your controller, letting you run logic – authentication checks, rate limiting, request logging – before a single line of controller code executes. Laravel ships with a clean set of built-in middleware, and writing your own is a matter of implementing one method.
Artisan generates controllers, models, migrations, and tests so you are never writing repetitive scaffolding by hand. Run php artisan list to see everything it can do – most beginners find the list considerably longer than expected.
Next Steps
With your posts page working, work through these in order:
- Add create and store methods to
PostControllerand a form view so users can submit new posts. - Build a resourceful controller –
php artisan make:controller PostController --resourcegenerates all seven RESTful methods in one command. Replace your existing controller with this and wire up the routes. - Explore Blade directives –
@extends,@section, and@includelet you build a shared layout so you are not duplicating your HTML on every page. - Add validation – call
$request->validate([...])in your store method before touching the database. Laravel returns clear error messages to the view automatically. - Scaffold authentication – run
composer require laravel/breezethenphp artisan breeze:installto add a full login and registration system in minutes.
If you want to compare Laravel’s conventions with another full-stack framework, our guide on Python Django full stack development covers similar MVC concepts from a Python perspective.
PHP began with a reputation for messy, inconsistent code – and a fair amount of that reputation was deserved. Laravel’s lasting achievement has been demonstrating that elegant, maintainable PHP is not an exception. It is the default, if you follow the framework’s conventions from the beginning. The posts page you just built is proof of that.
If you are building a Laravel application for a business and would like experienced development support, the team at DRS Web Solutions can plan and deliver your project.
Frequently Asked Questions
Q: What version of PHP do I need for Laravel 12?
A: Laravel 12 requires PHP 8.2 or higher [citation needed]. Run php -v in your terminal to check your current version. If your version is older, upgrade PHP before attempting installation – Laravel 12 will not install on anything below 8.2.
Q: How do I create and run a new Laravel 12 project?
A: Run composer create-project laravel/laravel my-project to create the project, then cd my-project and php artisan serve to start the development server. Your application will be available at http://127.0.0.1:8000.
Q: What is the MVC pattern in Laravel and why does it matter?
A: MVC stands for Model-View-Controller. Routes (in routes/web.php) direct requests to controllers (in app/Http/Controllers/), which prepare data and pass it to Blade views (in resources/views/). Each layer handles one responsibility, which keeps the codebase organised and testable as the application grows.
Q: Is Laravel 12 still worth learning now that Laravel 13 is in development?
A: Yes. Laravel 12 is actively maintained and widely deployed in production. Laravel follows a predictable annual release cycle, and the skills you build in version 12 transfer directly to version 13 – the upgrade path is well-documented and incremental.
Q: What does Laravel 12 include out of the box?
A: Laravel 12 ships with authentication and authorisation, the Eloquent ORM, routing and middleware, REST API scaffolding, a background job queue, task scheduling, caching, and database migrations – all available without installing additional packages.
Source: https://namixsoft.com/blog/laravel-12-complete-guide-for-beginners
This article was researched and written with AI assistance, then reviewed for accuracy and quality. Kev Parker uses AI tools to help produce content faster while maintaining editorial standards.
Need help with your web project?
From one-day launches to full-scale builds, DRS Web Development delivers modern, fast websites.




