Access Control
Three attributes
Each can be placed on the class or on a single method.
| Attribute | Checks | On failure |
|---|---|---|
#[RequiresAuth] | Auth::check() | policy: please log in |
#[RequiresVerified] | Logged in with a verified email | policy: not verified |
#[Authorize('ability', Model::class?, arg: 'id')] | Gate / policy; repeatable | policy |
#[RequiresAuth] // whole component: every method needs login
#[Authorize('manage-inventory')] // whole component: every method passes this Gate
class WarehouseLinker extends LinkerComponent
{
#[Computable]
#[RequiresVerified] // this one also needs a verified email
#[Authorize('adjust', WarehouseStock::class, arg: 'stock')]
public function adjust(array $args): LinkerResponse { … }
}arg: 'stock' means: take the id from the stock argument, load the WarehouseStock, and pass it to the policy's adjust(). If the record isn't found, access is denied.
Rules
- They only add up; they never relax. A method can add conditions but never remove the class's. A new method you forget to annotate is as strict as the others, not a hole.
- Rules on parent classes are inherited.
- Fixed order: login → email → permission → argument validation. Without permission, a caller never sees the
#[Validate]field rules. - Stateful and Stateless go through the same
dispatch().#[Computable(cache: true)]checks permission before reading the cache.
Route middleware doesn't count
The Linker endpoint is shared by all components. auth and can: on a page route only affect page requests. Permissions for Linker calls must be declared on the component.
Restricting which pages may call it
public function allowsRefererUrls(): array
{
return ['ticket.index', 'ticket.view']; // or ['/ticket/*']
}Entries starting with a slash match paths (wildcards allowed); others match route names. An empty array means no restriction. For full control, override allowsRefererUrlHandler(?string $referer): bool.
This is not authorization. It stops other websites from embedding your endpoint, but curl can send any Referer it likes. Treat it as a way to shrink the exposed surface.
Auditing
php artisan linker:list --methodsLists every component's #[Computable] methods, the arguments each accepts, and the effective access rules (class + method merged). To know "the most the browser can make the server do", this output is enough.