Laravel 10 is a legacy learning context
This guide explains a small Laravel 10 application for readers maintaining that version. It is not a recommendation to start a new production application on Laravel 10. Its original May 2025 publication date is preserved; the code and guidance were reviewed in November 2026.
Laravel’s release policy lists PHP 8.1–8.3 for Laravel 10 and security support ending on 4 February 2025. Use a supported framework release for new work and plan upgrades for existing installations. Do not assume a higher PHP version is automatically compatible with this legacy stack.
The example covers listing, creating and storing posts. It is deliberately not advertised as complete CRUD: editing and deleting are not implemented. Authentication here uses Laravel’s HTTP Basic middleware for a bounded local exercise; a public product needs a suitable account lifecycle and authorisation policy.
1. Create an isolated learning application
Use PHP 8.2, Composer and SQLite with the required PHP extensions enabled. Keep this exercise on your own machine, bound to loopback. The version constraint matters: an unpinned create-project command installs a different major release over time.
composer create-project laravel/laravel laravel10app "10.*"
cd laravel10app
php artisan make:model Post -m
php artisan make:controller PostController
If Composer reports security advisories or incompatible dependencies, stop and inspect them. Do not disable its security controls to make this old tutorial install. Use the files as a maintenance reference or reproduce in an appropriately isolated legacy test environment.
Create an empty database/database.sqlite file. In the local .env, set DB_CONNECTION=sqlite and remove the other DB_* settings so the default SQLite path is used. Never overwrite an existing application’s configuration or database for this exercise. The generated project normally includes .env and an application key; if absent, copy .env.example to .env and run php artisan key:generate once for this new application.
2. Understand the request path
| Location | Responsibility |
|---|---|
| routes/web.php | Match a URL and apply web middleware |
| app/Http/Controllers | Validate and coordinate the request |
| app/Models | Persist allowed data through Eloquent |
| database/migrations | Version the database structure |
| resources/views | Render escaped output with Blade |
A controller should not trust the submitted field list. The database and model should also reflect the intended data shape.
3. Define the migration and model
Replace the generated posts migration with the following complete file, preserving its generated filename:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title', 200);
$table->text('content');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('posts');
}
};
Replace app/Models/Post.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable = ['title', 'content'];
}
The fillable list limits mass assignment. It does not replace validation or authorisation. See the version-specific Eloquent documentation.
4. Validate only the data you intend to store
Replace app/Http/Controllers/PostController.php:
<?php
namespace App\Http\Controllers;
use App\Models\Post;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class PostController extends Controller
{
public function index(): View
{
return view('posts.index', [
'posts' => Post::query()->latest('id')->paginate(10),
]);
}
public function create(): View
{
return view('posts.create');
}
public function store(Request $request): RedirectResponse
{
$validated = $request->validate([
'title' => ['required', 'string', 'max:200'],
'content' => ['required', 'string', 'max:20000'],
]);
Post::create($validated);
return redirect()->route('posts.index')
->with('status', 'Post created.');
}
}
Only the validated result reaches create(). Do not use $request->all(). For a larger application, move reusable rules into a Form Request and authorise the action there or through a policy. Laravel 10 validation explains the request lifecycle.
5. Register only implemented actions
Replace routes/web.php for this new learning application:
<?php
use App\Http\Controllers\PostController;
use Illuminate\Support\Facades\Route;
Route::resource('posts', PostController::class)
->only(['index', 'create', 'store'])
->middleware('auth.basic');
All three actions require an existing user. For this local demonstration, create one interactively after migration with php artisan tinker, using your own local email and a unique password:
\App\Models\User::create([
'name' => 'Local reader',
'email' => 'reader@example.test',
'password' => \Illuminate\Support\Facades\Hash::make(readline('Local-only password: ')),
]);
Use a disposable password here: terminal input may be visible and history handling varies. Never reuse a real account password. HTTP Basic is a teaching boundary, not a complete account system. Use HTTPS outside loopback, rate limiting and an appropriate session or token authentication flow for the actual product. Every authenticated user in this exercise can create and read every post; multi-user ownership is not implemented.
6. Render escaped content and accessible forms
Create resources/views/posts/index.blade.php:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Posts</title>
<main>
<h1>Posts</h1>
<a href="{{ route('posts.create') }}">Create a post</a>
@if (session('status'))
<p role="status">{{ session('status') }}</p>
@endif
@forelse ($posts as $post)
<article>
<h2>{{ $post->title }}</h2>
<p style="white-space: pre-wrap">{{ $post->content }}</p>
</article>
@empty
<p>No posts yet.</p>
@endforelse
{{ $posts->links() }}
</main>
</html>
Create resources/views/posts/create.blade.php:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Create a post</title>
<main>
<h1>Create a post</h1>
<a href="{{ route('posts.index') }}">Back to posts</a>
<form action="{{ route('posts.store') }}" method="POST">
@csrf
<label for="title">Title</label>
<input id="title" name="title" value="{{ old('title') }}"
maxlength="200" required aria-describedby="title-error">
<p id="title-error">@error('title') {{ $message }} @enderror</p>
<label for="content">Content</label>
<textarea id="content" name="content" required maxlength="20000"
aria-describedby="content-error">{{ old('content') }}</textarea>
<p id="content-error">@error('content') {{ $message }} @enderror</p>
<button type="submit">Create post</button>
</form>
</main>
</html>
Blade’s escaped output is intentional; do not replace it with raw HTML rendering for user content. The CSRF field belongs in the web form. Client-side limits improve feedback but server validation remains authoritative.
7. Run and verify locally
php artisan migrate
php artisan route:list --path=posts
php artisan serve --host=127.0.0.1
Open /posts, sign in through the browser’s Basic prompt and create a post. Check empty and overlong submissions, escaped HTML-like text, success feedback and pagination. Unauthenticated requests must receive 401. Repeat requests can create duplicate posts here; idempotent submission is outside this small example.
The revised migration example was exercised on PHP 8.2.12 and Laravel 10.50.4: six framework tests passed with 34 assertions covering unauthenticated access, validated writes, rejected fields, escaped output, pagination and limited routes. Framework HTTP tests bypass CSRF by default; they do not alone establish browser CSRF behaviour. See the implementation report for the separate checks and limitations.
8. Diagnose failures before changing state
| Symptom | First check |
|---|---|
| Database connection fails | SQLite extension, file existence and selected connection |
| Route returns 404 | Route list, requested method and stale route cache |
| Write raises a mass-assignment error | Model fillable fields and validated payload |
| Form returns 419 | Session, cookies and CSRF token; do not disable protection |
| Basic authentication returns 401 | Local user email and hashed password |
Do not rerun destructive migrations on an existing database as a troubleshooting shortcut.
9. Production is a separate upgrade and release task
Upgrade this unsupported framework before public deployment. Review authentication, authorisation, tests and dependencies against the chosen supported version. Serve only the application’s public directory; keep .env private, set APP_DEBUG=false and grant only necessary write permissions to storage and bootstrap/cache.
Use the deployment environment’s configuration mechanism. Laravel does not automatically select a file named .env.production in every deployment arrangement. Build configuration, route and view caches only after validating the release environment. Do not regenerate an existing production encryption key casually.
Back up and test restoration before schema changes. Prepare rollback steps and monitor real application errors. For an inherited installation, Laravel maintenance begins with version and dependency inventory rather than replacing version numbers in code samples.

