Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Integer Field Type Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Via the control panel – go to Streams → Fields → Create, pick the integer type, and set min / max in the field config.
  2. Via a migration in your own addon:
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.

Implementation Patterns

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.

Gotchas and Tips

  • Low-maturity risk. 0 stars, 0 dependents, and a 0.27 score means it is effectively unmaintained. It is MIT-licensed and trivial (~one class + one Twig view), so vendoring or forking it into your addon is a reasonable hedge. Do not plan critical logic on future upstream fixes.
  • 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.
  • Nullable vs empty string. The stock Laravel 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.
  • Value is not cast automatically. The field type validates on save but does not guarantee strict 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.
  • Cache after changes. After adding a field or tweaking config, 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.
  • View publishing. If you customize resources/views/input.twig, publish it (php artisan addon:publish anomaly.integer_field_type) rather than editing vendor/, otherwise upgrades wipe your changes.
  • Do not override getRules() with a hard return of ['integer'] in a subclass — you will silently drop required/nullable rules injected by the base field type.
  • Debugging tip. When validation silently passes on a non-integer, check that your form is actually resolving to this 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".
  • Integration tip. If you need integer fields inside a custom (non-Streams) Laravel form, you get more value from Laravel's native numeric|integer|min|max rules than from wiring this package in — its main benefit is the Streams/CP integration, not the validation logic itself.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels