Tips
Small things that save you a search, one idea each.
- CLI
Check which laravel you're running
Read more in the docs →Herd and the Composer installer also install a
laravelcommand.laravel --versionshould printLaravel CLI; if not, put~/.laravel/binfirst on yourPATH. - CLI
Import from app::, not your folder name
Read more in the docs →A project called
parcel-trackerstill has a library namedapp, so paths into it look likeapp::models::Parcel. Inside the library,crate::works too. - Database
Let SQLite create its own file
Read more in the docs →End a SQLite
DATABASE_URLwith?mode=rwcand the file appears on first connect:DATABASE_URL=sqlite://storage/app/dev.sqlite?mode=rwc - Routing
Let the parameter type do the validation
Read more in the docs →Params<u32>turns/page/twointo a404before your handler runs. NowhereNumber()needed.pub async fn page(Params(n): Params<u32>) -> String { format!("page {n}") } - Routing
Limit a URL segment to a few words with an enum
Read more in the docs →Take the parameter as an enum. Any value that isn’t a variant gets a
404.#[derive(Deserialize)] #[serde(rename_all = "lowercase")] pub enum Genre { Rock, Jazz, Classical } - Models
Bind models by slug in one place
Read more in the docs →Use
{concert:slug}on a single route, so/tickets/summer-jazz-nightfinds its concert. Or put#[model(route_key = "slug")]on the struct to make every route look concerts up by slug. - Routing
Filter route:list by handler
Read more in the docs →laravel route:list --handler=concerts -v-vadds the middleware on each route, and--jsonis there for scripts. - Models
A column named query needs a rename
Read more in the docs →#[model]addsquery,find,create,updateanddelete, so a field can’t use those names. Rename the field and map it back with#[column("query")]. - Models
Bump a column on many rows in one query
Read more in the docs →Every flight still on the ground slips by 30 minutes, without loading a single row:
update!(Flight::query().filter(Flight::departed_at.is_null()) { delay_minutes += 30, }) .await?; - Workflows
Name every workflow before you deploy
Read more in the docs →Sleeping runs find their code by name, and the default is the module path. Set the name yourself and you can move the file later:
#[workflow(name = "billing.recover-payment")] - Workflows
Workflow sleeps need a queue that delays
Read more in the docs →database,redisandsqscan delay jobs. SQS FIFO can’t, and onsynca run stops at its first sleep. - Deploy
Point health checks at /up
Read more in the docs →It returns
200once the app has booted. Change or remove it insrc/app.rs.