Course › Week 6 · Laravel Go › Day 1 · lesson 36 of 42 · 20 min reading + 45 min practice
Laravel Go: install and the shape of an app
The CLI, a new application, and every folder next to the PHP Laravel one it stands for.
On this page
On 2 December 2026 the Laravel team released Laravel for Go: routing, validation, models, migrations, queues, workflows and testing helpers, with the names and habits of the PHP framework, written in Go. Week 5 built all of that by hand on net/http; this week the framework does it, and you see what it decides for you.
The whole week is pinned to v0.1.1, the version every example here was built and run with. It is a beta: the docs warn that releases before 1.0 may break APIs. Today: a new application, what each folder is, how it starts, and a first route of your own.
The framework
1. What Laravel Go is
Laravel Go is built on net/http. Your application is an http.Handler, each request runs in its own goroutine (the goroutines lesson), and a request embeds the standard *http.Request, so everything the routing lesson taught still applies underneath.
On top, it adds what a Laravel developer expects: route files, middleware groups, Validate into a struct, models and a query builder, migrations written in Go, a queue with a worker, console commands, and an HTTP test client. A new app is full-stack, with Inertia, React and TypeScript for its pages. This course uses only its API side: Week 5’s services were APIs, and the Go part is what this course teaches.
2. Creating an application
You need Go 1.27 or later (the setup page installed 1.27.4), Node.js for the frontend, and Git. The laravel command that creates Go apps is a new CLI, installed with one line on macOS and Linux:
curl -fsSL https://laravel.com/install.sh | sh
# open a new terminal, then:
laravel --version
laravel new nordic --go
cd nordic
The installer puts laravel in ~/.laravel/bin. Herd and the older Composer installer also have a laravel command: if laravel --version does not start with Laravel CLI, another one comes first on your PATH.
laravel new nordic --go downloads the starter app, writes .env from .env.example with a new APP_KEY, installs the npm packages and compiles the app. Without --go it asks which language you want. Whatever the folder is called, the Go module is always named app, so your own packages are imported as app/models, app/handlers/status.
The shape of an app
3. Every folder, next to the PHP one
| Laravel Go | What it holds | PHP Laravel |
|---|---|---|
main.go | the entry point: serves, or runs a command | public/index.php and artisan |
bootstrap/app.go | one Options function that lists routes, middleware, migrations, jobs, commands, services | bootstrap/app.php plus package discovery |
routes/web.go, routes/api.go | route functions; api.go routes get the /api prefix | routes/web.php, routes/api.php |
handlers/<resource>/ | one package per resource: posts.Index, posts.Store | app/Http/Controllers/ |
models/ | models: plain structs | app/Models/ |
database/migrations/ | migrations as Go files, listed in migrations.All | database/migrations/ |
jobs/, commands/, listeners/, events/ | queued jobs, console commands and the schedule, listeners, events | app/Jobs/, app/Console/, app/Listeners/, app/Events/ |
services/services.go | the long-lived things handlers share, like an API client | service providers and container bindings |
.env | every setting; there is no config/ folder | .env and config/*.php |
tests/feature/ | tests through the whole app | tests/Feature/ |
There is no app/ folder: the packages sit at the root, and the module’s name supplies the app/ in their import paths. Middleware has no folder of its own either. It lives in the package of the feature it belongs to, like billing.Subscribed in billing/.
4. main.go
The whole entry point is one line in main:
package main
import (
laravel "go.laravel.com"
"app/bootstrap"
)
func main() {
laravel.Run(bootstrap.Options())
}
bootstrap.Options() describes the application, and laravel.Run builds it and looks at the arguments: with none, it serves; with a command name, such as migrate, it runs that command and exits. One binary does what public/index.php and artisan do in PHP.
5. bootstrap/app.go: the one list of everything
Options returns a laravel.Options struct. This is the file as the starter ships it:
package bootstrap
import (
laravel "go.laravel.com"
"go.laravel.com/auth"
"go.laravel.com/config"
"go.laravel.com/db"
"go.laravel.com/db/postgres"
"go.laravel.com/inertia"
"go.laravel.com/web"
"app/commands"
"app/database/migrations"
"app/database/schema"
"app/database/seeders"
"app/jobs"
"app/listeners"
"app/models"
"app/resources"
"app/routes"
"app/services"
)
func Options() laravel.Options {
return laravel.Options{
Routes: laravel.Routes{
Web: routes.Web,
API: routes.API,
Channels: routes.Channels,
Health: "/up",
},
Middleware: func(m *laravel.Middleware, cfg *config.Config) {
m.Web.Append(auth.Session[models.User]{})
m.Web.Append(inertia.Middleware{
Share: share,
ErrorPage: "Error",
})
},
Views: resources.Views,
Drivers: []db.Driver{postgres.Driver},
Migrations: migrations.All,
Schema: schema.Dumps,
Seeders: seeders.All,
Commands: commands.All,
Schedule: commands.Schedule,
Listeners: listeners.All,
Jobs: jobs.All,
Services: laravel.BuildServices(services.New),
}
}
func share(r *web.Request) (inertia.Props, error) {
return inertia.Props{
"name": config.From(r).App.Name,
"status": r.Session().Get("status"),
}, nil
}
Routes names the route functions and the health-check path. Middleware adds session authentication and Inertia to the web group. Drivers picks PostgreSQL. Migrations, Commands, Jobs and Listeners are slices that each package keeps, such as migrations.All. Services builds your services once, at startup.
This is the biggest habit to change: Laravel Go does not look through your folders. PHP Laravel discovers commands, listeners and migrations by scanning directories; Go has no way to load code at runtime, so the binary contains only what this function lists. A job that is not in jobs.All cannot be dispatched (the dispatch returns an error that says so), and a listener that is not in listeners.All is never called, with no warning at all.
6. .env, and the port
The app reads every setting from .env. The checks on this site use the starter’s .env.example with a new key and two changes:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Qm5QV1Nv374158x9ypRJvdMRIhFfK44vhsUoQ9Qgc4A=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8080
SERVER_PORT=8080
DATABASE_URL=postgres://postgres@127.0.0.1/laravel
QUEUE_CONNECTION=database
The server listens on SERVER_PORT, 8000 by default. The course’s stand-in PHP Laravel API (the HTTP client lesson) already uses 8000, and this week still calls it, so the Go app moves to 8080. APP_URL follows, because the app builds its links from it.
DATABASE_URL points at a PostgreSQL database named laravel, the starter’s default; the Week 4 database nordic stays as it was. Like any .env, this one holds secrets (APP_KEY encrypts cookies and sessions), so it is never committed. The key shown here exists only for the checks of this site.
Running it
7. Commands: laravel migrate, go run . migrate, ./app migrate
In the app’s folder, laravel migrate compiles the app and runs its migrate command; it prints the compiler’s output only when the build fails. Where the CLI is not installed, go run . migrate does the same. This site builds once with go build -o app . and then runs ./app <command>, so what you see below is exactly the binary’s output.
The starter’s API route file, unchanged, and three commands run against it:
package routes
import (
laravel "go.laravel.com"
"go.laravel.com/config"
"go.laravel.com/routing"
"go.laravel.com/web"
)
func API(route *routing.Router, cfg *config.Config) {
route.Get("/version", version)
}
func version(*web.Request) *web.Response {
return web.JSON(map[string]string{"laravel": laravel.Version})
}
Method URI Name Handler
GET|HEAD /up health check
GET|HEAD / welcome.Show
GET|HEAD /api/version routes.version
POST /broadcasting/auth routing.(*Channels).Authorize
ANY /{fallback...} Closure
ANY /api/{fallback...} go.laravel.com.notFound
ANY /storage/private/local/{fallback...} storage.local go.laravel.com.mountedDisk.serve
ANY /storage/{fallback...} storage.public go.laravel.com.mountedDisk.serveMigrating `0001_01_01_000000_create_users_table`...
Migrating `0001_01_01_000001_create_cache_table`...
Migrating `0001_01_01_000002_create_jobs_table`...
3 migrations ran.Migration Batch Status
0001_01_01_000000_create_users_table 1 ran
0001_01_01_000001_create_cache_table 1 ran
0001_01_01_000002_create_jobs_table 1 ranroute:list is php artisan route:list: /api/version comes from this file, /up from Health in bootstrap/app.go, / from routes/web.go, and the {fallback...} routes answer everything else. The handler column names Go functions, like routes.version.
migrate ran the starter’s three migrations: users and sessions, the cache, and the queue’s tables. Here the database already existed. When it does not, laravel migrate asks whether to create it; without a terminal to ask in, it stops and tells you to pass --force.
8. Serving
With no arguments, the binary is the web server. Two requests to the same app:
HTTP/1.1 200 OK
Content-Length: 19
Content-Type: application/json
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: b1d1200a1a2a10c0407c06931e15f0ad
{"laravel":"0.1.0"}HTTP/1.1 404 Not Found
Content-Length: 23
Content-Type: application/json
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: 079d5b2e781e8228948141b18ba57df3
{"message":"Not Found"}Server running at `http://127.0.0.1:8080`. Press Ctrl+C to stop.
GET 200 /api/version 0.2ms
GET 404 /api/bookings 0.5ms
Stopping. Waiting up to 20s for the work in progress.The version route answers JSON. The constant laravel.Version says 0.1.0 in the v0.1.1 release; the module version in go.mod is the one to trust.
A path no API route matches is a 404 in JSON: errors of routes in api.go are always JSON. Every response carries an X-Request-Id, which Laravel also adds to what that request logs through slog’s context functions (the slog lesson), and security headers you did not write (X-Content-Type-Options, X-Frame-Options).
The log shows one line per request, then Ctrl-C: the app stops taking new requests and waits for the ones in progress, the graceful shutdown the tests and shutdown lesson wrote by hand, already built in.
A first handler
9. A handler package
A handler has one signature: func(r *web.Request) *web.Response. It returns the response instead of writing to a ResponseWriter. Handlers live in a package per resource under handlers/; this one reports the app’s name and environment.
package status
import (
"go.laravel.com/config"
"go.laravel.com/web"
)
type Status struct {
Name string `json:"name"`
Env config.Environment `json:"env"`
}
func Show(r *web.Request) *web.Response {
app := config.From(r).App
return web.JSON(Status{Name: app.Name, Env: app.Env})
}
config.From(r) returns the app’s configuration from the request. r is a context.Context too (the context lesson), and the framework keeps its application in it, so any function that takes a ctx can reach the config, the database or the services the same way.
web.JSON(value) encodes with encoding/json/v2, which does not sort map keys (the JSON lesson). A struct keeps the fields in a fixed order, so the response is the same on every call.
10. The route
routes/api.go imports the package by its path in the module and adds one line:
package routes
import (
laravel "go.laravel.com"
"go.laravel.com/config"
"go.laravel.com/routing"
"go.laravel.com/web"
"app/handlers/status"
)
func API(route *routing.Router, cfg *config.Config) {
route.Get("/version", version)
route.Get("/status", status.Show)
}
func version(*web.Request) *web.Response {
return web.JSON(map[string]string{"laravel": laravel.Version})
}
Method URI Handler
GET|HEAD /api/version routes.version
GET|HEAD /api/status status.Show
ANY /api/{fallback...} go.laravel.com.notFoundHTTP/1.1 200 OK
Content-Length: 32
Content-Type: application/json
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: 93a63e69955806da782ec9fca6f9250f
{"name":"Laravel","env":"local"}Server running at `http://127.0.0.1:8080`. Press Ctrl+C to stop.
GET 200 /api/status 0.2ms
Stopping. Waiting up to 20s for the work in progress.route.Get("/status", status.Show) reads like Route::get('/status', [StatusController::class, 'show']), but status.Show is the function itself. A typo in it is a compile error, not a runtime “method does not exist”. --path=api filters route:list, like artisan’s --path.
"name":"Laravel" is APP_NAME from .env; "env":"local" is APP_ENV.
11. services.go
The other file every app has, still empty in the starter:
package services
import (
"context"
laravel "go.laravel.com"
"go.laravel.com/config"
)
type Services struct{}
func New(env *config.Env, app *laravel.App) Services {
return Services{}
}
func From(ctx context.Context) *Services {
return laravel.ServicesOf[*Services](ctx)
}
The Services struct holds what lives as long as the app: an HTTP client for the PHP API, a payment provider’s client. New builds it once at startup from the .env values in env, and a handler reaches it with services.From(r). It is the dependency struct of the dependencies lesson, with the framework doing the wiring that main did there.
Every request shares what New built, from many goroutines at once, so each service must be safe for concurrent use, and nothing that belongs to one request (the logged-in user) goes in its fields.
Coming from PHP
<?php
use Illuminate\Support\Facades\Route;
Route::get('/status', fn () => [
'name' => config('app.name'),
'env' => app()->environment(),
]);
The PHP route is shorter, and it can be, because so much is found for you: config() is a global, the router file is loaded by convention, and php artisan discovers commands. Laravel Go keeps the names (routes, handlers, migrations, .env) and drops the discovery. Everything the app does is reachable from bootstrap.Options, the compiler checks every name in it, and the result is one binary with no PHP, no FPM and no vendor/ to deploy.
The price is in the same place: you list each job, command and listener yourself, and forgetting a listener fails silently.
PracticeThe framework’s own docs, offline; one more route
Every app carries the docs of its exact framework version inside the module. In the app’s folder, .agents/skills/writing-laravel-go-apps/scripts/docs-path.sh prints their folder (it runs go list -m -f '{{.Dir}}/docs' go.laravel.com). Read installation.md, structure.md and lifecycle.md there: they are the version this week uses, which matters for a beta that may change.
Exercise: the time
Add GET /api/status/time, answered by status.Time, which returns {"now": "…"} with the server’s time from time.Now().Format(time.RFC3339). Check it with curl, then run ./app route:list --path=status and find both routes.
Remember
- Laravel Go runs only what
bootstrap.Optionslists: no folder is scanned, and a forgotten listener fails silently. - One binary is both the server and
artisan:./appserves,./app migrateruns a command. - A handler is
func(r *web.Request) *web.Response; answer with structs, so the JSON keeps its order.
Tomorrow: route parameters, groups, middleware, and validation into a typed struct.