Responses & Actions
The server doesn't send JavaScript. It sends "which named action to run".
LinkerResponse
// Success: data is written to client state
return $this->ok(['matchCount' => 12]);
// Failure
return LinkerResponse::validation(['email' => ['Already taken']]);
return LinkerResponse::policy();
return $this->service('Inventory service is temporarily unavailable');| Constructor | kind |
|---|---|
ok($data) | Success |
validation($errors) | Field errors (a failed #[Validate] produces this too) |
policy($message?) | Not permitted |
service($message) | Business failure; the message is shown to the user |
expired() / conflict() | Usually returned by the framework; you rarely call them |
Pipeline
return $this->ok()
->call('ui.toast', ['level' => 'success', 'message' => 'Saved'])
->then('state.clear', ['scope' => 'customerForm'])
->then('render.fragment', ['target' => '#list', 'name' => CustomerController::class, 'params' => ['mode' => 'results']]);| Method | When it runs |
|---|---|
->call() / ->then() | The call succeeded and no earlier step failed |
->catch() | The call failed, or an earlier step threw |
->always() | Always |
The pipeline still runs when the whole call fails; it just starts in the "failed" state, so only catch and always run. This is useful for multi-step forms submitted at once, where the field in error may be on a hidden step:
return LinkerResponse::validation($errors)
->catch('state.set', ['scope' => 'ticketQuickWizard', 'key' => 'step', 'value' => 2]);On failure data is not written to client state; only the pipeline runs.
Built-in actions
php artisan linker:list is the authority.
| Action | Arguments | Effect |
|---|---|---|
dom.scrollTo | target | Scroll to an element |
dom.class | target, class, on? | Toggle a class |
dom.repeat | items, ref?, mode? | Render a list from a template row; see dom.repeat |
form.focus | target | Focus a field |
form.reset | target? | Reset a form |
state.set | scope, key, value | Write client state |
state.clear | scope | Clear a namespace |
render.fragment | target, name, params?, fresh? | Ask renderBlade to re-render a block |
render.page | name, params?, url? | Replace the whole page |
ui.toast | level, message | Notification |
ui.confirm | message, title?, label?, target?, level?, destructive? | Confirmation; returns Promise<boolean> and the pipeline waits |
This list is the complete answer to "what is the most the server can make the browser do". The implementations are in resources/js/linker/actions.js, the argument specs in LinkerServiceProvider::registerActions(), one-to-one.
Adding an action
Touching two files is deliberate: the capability list should stay small enough for one person to read. The generator makes sure both sides are right the first time:
php artisan make:linker-action ui.spinner target:string on:bool?Types: string int number bool array mixed, with a trailing ? for optional. Types are checked at registration time, so a typo can't slip through.
linker:list belongs in CI: a missing JS side only shows up as "the pipeline fails at that step". More in Governing Actions.