Skip to main content

What is the InteractsWithData trait?

Illuminate\Support\Traits\InteractsWithData is a trait that groups common APIs for array-like input data. The trait itself requires only two abstract methods: all() and data(). Each class provides its own data retrieval logic. In return, the trait gives you many high-frequency methods:
  • Presence checks: has(), hasAny(), exists(), missing()
  • Emptiness checks: filled(), isNotFilled(), anyFilled()
  • Conditional execution: whenHas(), whenFilled(), whenMissing()
  • Extraction: only(), except()
  • Type conversion: string(), boolean(), integer(), float(), date(), enum(), collect()

Relationship to Request methods

Illuminate\Http\Request from the request() helper uses InteractsWithData through Concerns\InteractsWithInput. So everyday input access patterns are provided through this trait:
Request::get() is a Symfony-compatible method defined in the Request class itself. In Laravel 13 source code, it is explicitly marked @deprecated use ->input() instead, so input() is the recommended method.

Main implementations in Laravel core

Classes that directly use InteractsWithData

  • Illuminate\Session\Store implements similar APIs such as has(), get(), only(), and except() independently
  • Illuminate\Validation\Concerns\ValidatesAttributes provides validation judgment logic and is intentionally separate from input access APIs

Relationship between the trait and core classes

Add it to your package classes

InteractsWithData fits package classes that store input arrays and should expose Laravel-style access APIs.
1

Create a data container class

2

Read values safely with typed accessors

Practical use cases

  • Option bags for external API clients
  • Normalization layers for webhook payloads
  • Configuration override resolver classes in packages
If you implement only all() and data(), you avoid rebuilding input access APIs repeatedly and lower maintenance cost.
Last modified on July 13, 2026