anomaly/integer-field_type
The Integer Field Type addon for Anomaly's Streams platform adds a simple numeric input for storing whole numbers in Laravel-powered CMS entries. It integrates with Streams fields, forms, and database storage for custom content types.
This package is a field type addon for PyroCMS / the Streams Platform (anomaly/streams-platform), not a standalone library. It ships a single concern: registration of an integer field type so streams, form builders, and the CP can render and validate integer values. It is auto-discovered by the Streams addon scanner — there is no separate artisan command needed for installation beyond composer.
Minimal steps:
composer require anomaly/integer-field_type
Then either:
integer type, and set min / max in the field config.public function up()
{
$stream = $this->streams->build('my_module', 'widgets');
$stream->addField('quantity', 'integer', [
'min' => 1,
'max' => 999,
'required' => true,
]);
}
Look first at these files in the repo:
src/IntegerFieldType.php — the actual field type class (rules, config schema, default values).src/IntegerFieldTypePresenter.php — formatting helpers used in views.resources/views/input.twig — the CP form input (uses type="number" and min/max attributes when configured).resources/lang/en/addon.php — the name/description shown in the field type picker.First real use case: add an integer attribute to an existing stream (e.g. stock_count on a products stream) and read it back on an entry:
$product->stock_count; // cast via the field type
$product->presenter()->stock_count; // if you add a presenter method
If it does not appear in the field picker, run php artisan addon:scan (or php artisan clear-compiled) — the Streams addon registry caches the field type list.
Defining fields on a stream (migration pattern). The idiomatic use is inside a Streams migration in your own module addon. Pass min/max through the config array; these become both validation rules and HTML attributes on the CP input.
$stream->addField('rating', 'integer', [
'min' => 0,
'max' => 5,
'required' => true,
]);
Using it in forms / form builders. The field type works with the FormBuilder and Form classes without changes:
$form->add('quantity', 'integer', ['label' => 'Quantity']);
If you are building a custom addon form, you can also bind it through FormBuilder::on('widgets') and add the integer field by slug — validation is inherited from getRules().
Reading the value. Entry accessors return the raw column value plus a presenter:
$entry->quantity; // int|null
$entry->presenter()->quantity; // through IntegerFieldTypePresenter
Validation is the whole point. The package exists mostly so that integer, min, max, nullable, and required are applied consistently at the field-type level. If your stream rules are not firing, inspect IntegerFieldType::getRules() — it merges the parent class rules with its own config-driven ones. Extend it (see below) rather than duplicating validation at the form layer.
Extending the field type. Because it is a plain class with a $rules/$config contract, the clean pattern is to subclass and override:
namespace Acme\Widgets\FieldType;
use Anomaly\IntegerFieldType\IntegerFieldType;
class PositiveIntegerFieldType extends IntegerFieldType
{
protected $config = ['min' => 1, 'max' => null];
public function getRules()
{
return array_merge(parent::getRules(), ['numeric']);
}
}
Register it in your addon's service provider as a field type and it will appear alongside the built-in integer type. This is the intended extension point — the package exposes config and rules but keeps the input view minimal.
Twig integration. Since Streams renders the CP in Twig, your custom views can reuse the field type's presenter:
{{ entry.quantity.presenter.value }}
Workflow tip. For day-to-day work, treat this as a schema primitive: it should only ever own the "this value is an integer in a range" concern. Any display formatting, units, or coercion to currency belongs in your own presenter or decorator, not in field type config.
min / max semantics. They are applied as both HTML5 attributes and Laravel validation rules. If you pass them as strings from a migration, ensure they remain numeric — Streams may store them as-is in the field config array, which can break the integer HTML attribute or result in min="0" being silently dropped by the browser if the string is empty.integer rule fails on ''. If the field is optional, mark it nullable in the stream config or the CP will reject a blank submission. There is no built-in nullable toggle in this package's config — it comes from the base FieldType class, so confirm it is set at the assignment level.int on read. If you see "5" instead of 5 from $entry->quantity, cast at the model boundary or add a cast/presenter method — do not expect this package to solve that.php artisan clear-compiled (and, in older Streams versions, php artisan streams:compile) may be required before the CP renders the new min/max attributes. Field type definitions are cached aggressively.resources/views/input.twig, publish it (php artisan addon:publish anomaly.integer_field_type) rather than editing vendor/, otherwise upgrades wipe your changes.getRules() with a hard return of ['integer'] in a subclass — you will silently drop required/nullable rules injected by the base field type.php artisan tinker and dumping $field->getType() on the assignment is the fastest way to confirm the addon is registered; a plain text fallback will happily accept "abc".numeric|integer|min|max rules than from wiring this package in — its main benefit is the Streams/CP integration, not the validation logic itself.How can I help you explore Laravel packages today?