Skip to content

Responses & Actions ​

The server doesn't send JavaScript. It sends "which named action to run".

LinkerResponse ​

php
// 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');
Constructorkind
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 ​

php
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']]);
MethodWhen 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:

php
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.

ActionArgumentsEffect
dom.scrollTotargetScroll to an element
dom.classtarget, class, on?Toggle a class
dom.repeatitems, ref?, mode?Render a list from a template row; see dom.repeat
form.focustargetFocus a field
form.resettarget?Reset a form
state.setscope, key, valueWrite client state
state.clearscopeClear a namespace
render.fragmenttarget, name, params?, fresh?Ask renderBlade to re-render a block
render.pagename, params?, url?Replace the whole page
ui.toastlevel, messageNotification
ui.confirmmessage, 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:

bash
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.