Tips

Small things that save you a search, one idea each.

  1. CLI

    Check which laravel you're running

    Herd and the Composer installer also install a laravel command. laravel --version should print Laravel CLI; if not, put ~/.laravel/bin first on your PATH.

    Read more in the docs →
  2. CLI

    Import from app::, not your folder name

    A project called parcel-tracker still has a library named app, so paths into it look like app::models::Parcel. Inside the library, crate:: works too.

    Read more in the docs →
  3. Database

    Let SQLite create its own file

    End a SQLite DATABASE_URL with ?mode=rwc and the file appears on first connect:

    DATABASE_URL=sqlite://storage/app/dev.sqlite?mode=rwc
    Read more in the docs →
  4. Routing

    Let the parameter type do the validation

    Params<u32> turns /page/two into a 404 before your handler runs. No whereNumber() needed.

    pub async fn page(Params(n): Params<u32>) -> String {
        format!("page {n}")
    }
    Read more in the docs →
  5. Routing

    Limit a URL segment to a few words with an enum

    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 }
    Read more in the docs →
  6. Models

    Bind models by slug in one place

    Use {concert:slug} on a single route, so /tickets/summer-jazz-night finds its concert. Or put #[model(route_key = "slug")] on the struct to make every route look concerts up by slug.

    Read more in the docs →
  7. Routing

    Filter route:list by handler

    laravel route:list --handler=concerts -v

    -v adds the middleware on each route, and --json is there for scripts.

    Read more in the docs →
  8. Models

    A column named query needs a rename

    #[model] adds query, find, create, update and delete, so a field can’t use those names. Rename the field and map it back with #[column("query")].

    Read more in the docs →
  9. Models

    Bump a column on many rows in one query

    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?;
    Read more in the docs →
  10. Workflows

    Name every workflow before you deploy

    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")]
    Read more in the docs →
  11. Workflows

    Workflow sleeps need a queue that delays

    database, redis and sqs can delay jobs. SQS FIFO can’t, and on sync a run stops at its first sleep.

    Read more in the docs →
  12. Deploy

    Point health checks at /up

    It returns 200 once the app has booted. Change or remove it in src/app.rs.

    Read more in the docs →