# @svelte-lean/query/laravel

> laravel(): the Laravel profile (envelope, refusals, 422 field errors, paginators, query strings, method spoofing), formData() and hasFiles().

Page: https://svelte-lean.vercel.app/query/api/laravel · Markdown: https://svelte-lean.vercel.app/query/api/laravel.md · Index: https://svelte-lean.vercel.app/llms.txt

laravel(): a profile for Laravel APIs. It unwraps the { success, data } envelope, turns refusals and 422 answers into typed errors, reads paginators and encodes query strings and multipart bodies.

## Import

`import`

```ts
import { laravel, formData, hasFiles } from '@svelte-lean/query/laravel';
```

## Usage

`src/lib/api/transport.ts`

```ts
// src/lib/api/transport.ts
import { http } from '@svelte-lean/query/http';
import { laravel } from '@svelte-lean/query/laravel';

export const transport = http({
	base: '/',
	profile: laravel({
		// An info code: `success: false` with this code is a success.
		accept: (envelope) => envelope.code === 'ALREADY_SYNCED',
		kind: (envelope) => (envelope.code === 'ACTION_NOT_AUTHORIZED' ? 'forbidden' : undefined),
		hints: { header: 'X-Invalidate', envelope: true }
	})
});
```

## Size

Production Vite builds of a small consumer entry, Svelte external. A marginal row is the bytes the entry adds over the row it names.

| Build | Over | gzip | brotli | Budget (gzip) |
| --- | --- | --- | --- | --- |
| `laravel (marginal)` | `http (marginal)` | 1681 B | 1548 B | 1900 B |

Read from `packages/query/artifacts/size.json`. Every entry and its method: [Performance](https://svelte-lean.vercel.app/query/performance.md).

## Functions

The profile and its multipart helpers.

### Exports

Runtime exports of the entry.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| # `laravel` | `(options?: LaravelOptions) => Profile` | – | The profile; pass it to http({ profile }). |
| # `formData` | `(value: object, options?: FormDataOptions) => FormData` | – | A nested object as Laravel multipart fields (bracket keys). |
| # `hasFiles` | `(value: unknown) => boolean` | – | True when a File or Blob is somewhere in the value. |

## Options

LaravelOptions, the argument of laravel().

### LaravelOptions

Every option has a default.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| # `envelope` | `boolean` | `true` | Read { success, data, message, code }. |
| # `methodSpoof` | `boolean \| 'always'` | `true` | Send multipart PUT, PATCH and DELETE as POST with \_method; 'always' JSON and body-less ones too. An endpoint's transport.methodSpoof wins. |
| # `booleans` | `'digits' \| 'words'` | `'digits'` | Multipart booleans as '1' and '0', or 'true' and 'false'. |
| # `accept` | `(envelope: Envelope) => boolean` | – | Info codes: a success: false envelope that is accepted is a success. |
| # `kind` | `(envelope) => 'refused' \| 'validation' \| 'forbidden' \| undefined` | – | Classify application refusals (ACTION\_NOT\_AUTHORIZED as forbidden). |
| # `hints` | `{ header?: string, envelope?: boolean }` | `off` | Server-driven freshness on mutation answers: the X-Invalidate header, and invalidate and refreshed beside data. |

### FormDataOptions

Options of formData() and of transport.multipart.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| # `booleans` | `'digits' \| 'words'` | `'digits'` | How booleans are written. |
| # `nulls` | `'skip' \| 'empty'` | `'skip'` | Leave nulls out, or send an empty string. |
| # `emptyArrays` | `'skip' \| 'empty' \| ((key) => boolean)` | `'skip'` | Leave empty arrays out, or send an empty string (per key with a function). |
| # `arrays` | `'indexed' \| 'brackets'` | `'indexed'` | Keys of array items: key\[0\] or key\[\] (scalars and files; objects keep their index). |

## Guide

How to use it, with examples: [Client setup](https://svelte-lean.vercel.app/query/client.md). All entry points: [Svelte Lean Query](https://svelte-lean.vercel.app/query.md).
