The package adds six commands. Most apps only ever type two of them:
php artisan rsc:install # once
php artisan make:rsc-action Orders --method=cancel # every new action| Command | What it does |
|---|---|
rsc:install |
sets the app up: config, secret, and the JavaScript half |
make:rsc-action |
writes a server action, or a class for rpc() |
rsc:host-manifest |
writes rsc-host.json, which the build reads |
rsc:cache |
caches the callables for production |
rsc:clear |
removes that cache |
rsc:prune-versions |
deletes old live-data versions from the table |
rsc:install
php artisan rsc:installSets the application up, in order:
- Publishes
config/rsc.php, unless it is already there. - Generates
RSC_HOST_CALL_SECRETinto.env, once. - Adds
rsc-kit/laraveltoboost.jsonwhen the app uses Laravel Boost, so Boost installs the package’s skill and keeps it current. - Runs
rsc-kit initfor the JavaScript half (bunxwhen Bun is there,npxotherwise), which asks its questions in a terminal and takes the defaults without one. - Says whether the installed
@rsc-kit/corematches the package.
| Option | What it does |
|---|---|
--force |
publishes config/rsc.php again over the one you have |
--skip-js |
does only the PHP half, and prints the rsc-kit init command to run yourself |
# In a Docker build, where Node runs in another stage
php artisan rsc:install --skip-jsGetting started has what lands in the app.
make:rsc-action
php artisan make:rsc-action Orders --method=cancel --authWrites a server action under app/Rsc/Actions, or with --rpc a class for
rpc() under app/Rsc, then writes the manifest so the action is importable
when the command returns. A dev server that is running starts again when the
manifest changes.
| Option | What it does |
|---|---|
name |
the class name, StudlyCase. A slash nests it: Billing/Invoices |
--method= |
a method per call, repeatable. None makes the class invokable |
--rpc |
a class for rpc() under app/Rsc, not an action |
--auth |
requires a signed-in visitor: #[Middleware('auth')] |
--can= |
a policy check, ability or ability,Model: #[Authorize]. Repeatable |
--middleware= |
a route middleware by name: #[Middleware]. Repeatable |
--revalidate= |
what the action makes stale, a section or page name: an Rsc::revalidate() line |
--form |
a public form: also writes the FormRequest and the form in resources/js/forms |
--force |
overwrites the class if it exists |
An action with several methods
php artisan make:rsc-action Orders --method=store --method=cancel --auth --revalidate=ordersimport * as orders from '../../server-actions/orders'
await orders.store(formData)
await orders.cancel(id)An invokable action
php artisan make:rsc-action ArchiveProject --auth --can=update,ProjectWith no --method, the class has an __invoke and the module’s default export
is the action:
import archiveProject from '../../server-actions/archive-project'
await archiveProject(projectId)A class for rpc()
php artisan make:rsc-action Dashboard --rpc --method=stats --method=recentWrites app/Rsc/Dashboard.php and prints how to reach it:
await rpc('Dashboard.stats'). The manifest is written too, since its names
are what rpc()’s first argument is checked against. --revalidate is for
actions and is left out of an rpc() class.
Nesting
php artisan make:rsc-action Billing/Invoices --method=sendWrites app/Rsc/Actions/Billing/Invoices.php in the App\Rsc\Actions\Billing
namespace, imported from server-actions/billing/invoices. Discovery looks
under every folder of app/Rsc.
A public form
php artisan make:rsc-action Contact --method=send --formWrites three files: the action app/Rsc/Actions/Contact.php, the form request
app/Http/Requests/SendContact.php (unless it exists), and the form
resources/js/forms/contact.ts. --form takes at most one --method, and
not --rpc: a form posts to one action. An existing form file is left as it
is. Public forms walks through
the three.
rsc:host-manifest
php artisan rsc:host-manifestWrites rsc-host.json at the app’s root: every server action, which the build
writes "use server" modules from, and every function rpc() can call, with
their types read from the PHP signatures. Classes are found by reflection over
app/Rsc, inherited methods included.
You rarely run it yourself. vite.config.ts runs it when vite and
vite build start, and make:rsc-action runs it after writing a class. Run
it before a typecheck in CI, which does not start Vite:
- run: php artisan rsc:host-manifest
- run: npx tsc --noEmit| Option | What it does |
|---|---|
--print |
writes the manifest to stdout instead of the file |
php artisan rsc:host-manifest --print | jq '.functions'The file is rewritten every time, so it is not committed.
rsc:cache
php artisan rsc:cacheWrites what discovery finds to bootstrap/cache/rsc-callables.php, so a host
call in production does not walk app/Rsc and reflect on every class before
running the one function it asked for. It is the same bargain as route:cache
and event:cache, and php artisan optimize runs it with theirs:
php artisan optimize # config, routes, events, views and rsc:cacheNothing reads the file unless it exists, so development never sees a stale
map. make:rsc-action writes it again when it finds one, so a class made
after optimize is not missing from it.
rsc:clear
php artisan rsc:clearDeletes the cached callables. php artisan optimize:clear runs it.
rsc:prune-versions
php artisan rsc:prune-versions
php artisan rsc:prune-versions --days=7Deletes live-data versions that nobody has
changed in a while, when they are kept in a table (RSC_VERSIONS=database).
Deleting is always safe: a tab still holding the name refreshes once.
| Option | What it does |
|---|---|
--days= |
deletes names not changed in this many days. The default is rsc.versions_keep_days (RSC_VERSIONS_KEEP_DAYS, 30) |
Schedule it:
use Illuminate\Support\Facades\Schedule;
Schedule::command('rsc:prune-versions')->daily();With versions in the cache, the default, there is nothing to prune: the keys
expire on their own after rsc.versions_keep_days, and the command says so.
From the JavaScript side
rsc-kit has commands of its own, run with bunx or npx:
bunx rsc-kit make:form Contact.send # a form around an existing actionBlueprints covers make:form.