What are Support contracts?
Illuminate\Contracts\Support contains small but important interfaces used across Laravel internals.Arrayable, Jsonable, Htmlable, and Responsable are especially useful when you want Value Objects, DTOs, and response objects to plug into Laravel behavior naturally.
All signatures in this page are verified against the Laravel
13.x branch in laravel/framework.1) Arrayable
Interface definition
Implementation example
Laravel core usage
Illuminate\Database\Eloquent\ModelimplementsArrayableand providestoArray()Illuminate\Http\JsonResponse::setData()detectsArrayableand encodestoArray()output
Package-development usage points
- Keep DTO / Value Object normalization in one place
- Let your objects flow through APIs that expect plain arrays without extra adapter code
2) Jsonable
Interface definition
Implementation example
Laravel core usage
Modelalso implementsJsonableand providestoJson($options = 0)JsonResponse::setData()givesJsonablepriority and callstoJson()
Package-development usage points
- Define strict JSON output shape for webhooks, API payloads, and logging
- Avoid implicit serializer behavior and keep domain-specific JSON explicit
3) Htmlable
Interface definition
Implementation example
Laravel core usage
Illuminate\Support\HtmlStringimplementsHtmlable- The
e()helper returnstoHtml()directly when given anHtmlableinstance
Package-development usage points
- Encapsulate trusted HTML fragments in dedicated objects
- Keep your Blade rendering boundaries clear when using
{!! ... !!}
4) Responsable
Interface definition
Implementation example
Laravel core usage
Illuminate\Routing\Router::toResponse()first checks forResponsableand callstoResponse($request)Illuminate\Http\Resources\Json\JsonResourceimplementsResponsable, so you can directlyreturn UserResource::make($user);
Package-development usage points
- Move HTTP response assembly out of controllers and into dedicated objects
- Return DTO-like objects directly from controllers while keeping presentation logic isolated
Implementation decision guide
You need reusable array conversion
Implement
Arrayable and centralize normalization logic in toArray().You need controlled JSON output
Implement
Jsonable and make toJson($options) your explicit serialization contract.Next pages to read
The Macroable trait
Learn the extension pattern for adding methods to existing classes.
The Conditionable trait
Learn conditional fluent chains with
when() and unless().tap() helper / Tappable
Learn side-effect-friendly chaining while returning the original value.
The Dumpable trait
Learn how to add
dump() / dd() style debugging to your own objects.