Server-side Checks
The gates a Linker call passes through
Permissions come before argument validation: callers without permission never see the field rules.
Practices
Every method must answer "who may call this?"
#[RequiresAuth] // class level: the whole component needs login
class InvoiceLinker extends LinkerComponent
{
#[Computable]
#[Validate(['id' => 'required|integer'])]
#[Authorize('view', Invoice::class, arg: 'id')] // method level: is this invoice theirs?
public function show(array $args): LinkerResponse { … }
}- Rules only add up, never relax. A new method you forget to annotate is as strict as the others.
- When
#[Authorize]names a model, it takes the id fromarg, loads it withfind(), and denies if nothing is found. authandcan:on page routes don't apply to Linker calls, because the Linker endpoint is shared.
Never assume "the front end already checked"
// ❌ The total sent by the browser can't be trusted
public function checkout(array $args): LinkerResponse
{
Order::create(['total' => $args['total']]);
}
// ✅ The server computes it
public function checkout(array $args): LinkerResponse
{
$total = Cart::for(auth()->user())->total();
Order::create(['total' => $total]);
}Guard flows with server state
#[Computable]
public function submit(array $args): LinkerResponse
{
if ($this->get('step') !== 3) { // the browser can't change this value
return LinkerResponse::policy();
}
…
}Make Stateless writes idempotent yourself
Stateless has no instance lock; the same URL can be called in parallel. Use DB transactions, unique constraints or idempotency keys for writes.
Pick renderBlade params explicitly
public function renderCallSafely(array $params = [], string $method = 'components'): View
{
// ✅ allow list + types
$mode = in_array($params['mode'] ?? '', ['list', 'detail'], true) ? $params['mode'] : 'list';
$id = (int) ($params['id'] ?? 0);
// ❌ never pass the whole array into a query or view
// return view('x', $params);
}@renderInline doesn't go through the request validation layer; the controller allow-list check is enforced inside it.
Caches must include the user
The key for #[Computable(cache: true)] always includes the user id and the arguments. Do the same when you write your own caching, or data leaks between users.
Debug output
$this->dump() / dd() only send content when APP_DEBUG=true. In production the output is still intercepted (so HTML can't break the JSON), but the content is dropped and only a warning is logged. Always run production with APP_DEBUG=false.
abort() and exceptions in business code
You can call abort() inside a method. The framework translates it into a kind the browser understands, rather than always fatal:
| Exception | kind |
|---|---|
abort(401) / abort(403) | policy |
abort(404) | service ("not found") |
abort(409) | conflict |
abort(422) | validation |
| Other HTTP exceptions | service |
Any other Throwable | fatal, and report()ed to the log |
In production the user gets one fixed sentence; exception details stay in the log.