What you'll learn
Transfer your framework-independent architecture into Laravel. Follow a request through the kernel, router, middleware, controller, service container, and Blade response while learning where Laravel conventions remove plumbing—not design decisions.
By the end of this lesson, you'll be able to:
- Navigate Laravel structure and Artisan
- Build routes, controllers, middleware, and Blade views
- Resolve application services through the container
Core mental model
Professional PHP is less about memorizing APIs and more about choosing a clear boundary for each responsibility. Use this table as a decision guide while reading the examples.
| Concept | What it protects | Decision rule |
|---|---|---|
| Service container | Dependency construction | Bind interfaces at infrastructure boundaries; auto-wire concrete services. |
| Middleware | Request pipeline policy | Apply authentication, throttling, and shared context outside controllers. |
| Blade | Escaped server rendering | Use components and layouts for presentation, never database access. |
Professional workflow
Build the feature in small, verifiable steps. Each step leaves the system in a state you can test.
- Describe the Laravel request lifecycle boundary: its inputs, outputs, invariants, and expected failures.
- Implement the smallest happy path behind an explicit contract.
- Add validation and translate low-level failures into language the caller understands.
- Exercise the boundary with realistic data, then inspect output, logs, and resource cleanup.
- Refactor only after behavior is protected by a repeatable check.
Make the boundary visible
Guided code lab
Route into an invokable controller
Named routes create stable URL generation and route model binding resolves the Course.
<?php
use App\Http\Controllers\ShowCourseController;
use Illuminate\Support\Facades\Route;
Route::get('/courses/{course:slug}', ShowCourseController::class)
->middleware('auth')
->name('courses.show');Inject a use case
Laravel resolves the controller and service; the controller still owns only HTTP concerns.
<?php
namespace App\Http\Controllers;
use App\Actions\BuildCoursePage;
use App\Models\Course;
use Illuminate\Contracts\View\View;
final readonly class ShowCourseController
{
public function __construct(private BuildCoursePage $page) {}
public function __invoke(Course $course): View
{
return view('courses.show', $this->page->handle($course));
}
}Production practice
Contract
Keep framework types at delivery and infrastructure edges; core rules remain ordinary typed PHP.
Verification
Use route and feature tests for framework behavior, and fast unit tests for application rules.
Operations
Cache config, routes, and views in production; keep debug mode off and health endpoints dependency-aware.
Common failure mode
Independent workshop
Build a Laravel course catalog with public pages, authenticated management routes, shared layouts, and a service-layer action.
Your finished workshop must include:
- Named resource routes and middleware
- Blade components with escaped output
- Container binding plus feature tests
Definition of done
Recap & quick check
Key takeaways
- Laravel conventions accelerate delivery.
- The container constructs dependency graphs.
- Controllers remain transport adapters.
- Blade escapes double-brace output by default.
Quick check
1. What resolves constructor dependencies?
2. Where should shared authentication policy live?
3. Should APP_DEBUG be true in production?
Keep the workshop: later phases deliberately build on these boundaries, so today's small example can become part of your portfolio architecture.