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

Boolean Field Type Laravel Package

anomaly/boolean-field_type

Anomaly Boolean Field Type adds a simple true/false toggle field type to Anomaly’s Laravel-based field type system, making it easy to store, edit, and manage boolean values cleanly in forms and entries.

View on GitHub
Deep Wiki
Context7

Getting Started

This is not a standalone Laravel package — it is a Streams Platform field type addon for PyroCMS / Laravel Streams (v3.x). Its only job is to register a boolean field type that renders a toggle switch in forms and casts to true/false on entity access. There is no runtime API to "learn"; you consume it through the Streams field system.

Requirements

  • A working PyroCMS/Streams install (Laravel 5.x–6.x era).
  • An addons/ or composer-based addon path already configured.

Install

composer require anomaly/boolean-field_type

Streams auto-discovers addon service providers, but you typically need to register it as an addon so its field type is registered in the FieldTypeRegistry:

php artisan addon:install anomaly/boolean-field_type
# or, after toggling composer versions:
php artisan addon:reinstall anomaly/boolean-field_type

Where to look first

  1. src/BooleanFieldTypeServiceProvider.php — confirms the field type slug (boolean) and input view namespace.
  2. src/BooleanFieldType.php — the config schema, input view, and any cast logic.
  3. resources/views/input.twig — how the toggle markup / hidden-input trick is done.

First use case

Add a field to any stream — either through the admin control panel (Assignment → add field → type Boolean), or in a migration:

$stream->addField('is_published', 'boolean', [
    'default_value' => true,
]);

Then in Twig:

{% if entry.is_published %}Published{% endif %}

Implementation Patterns

Stream definition via migration

The most common day-to-day use is declaring boolean flags on stream models:

use Anomaly\Streams\Platform\Database\Migration\Migration;

class CreateArticlesStream extends Migration
{
    public function up()
    {
        $this->stream()
            ->addField('is_active', 'boolean', ['default_value' => true])
            ->addField('is_featured', 'boolean', ['default_value' => false]);
    }
}

Boolean fields are cheap (single tinyint(1)), so flag columns are a natural fit — "published", "featured", "allow_comments", "is_verified", etc.

Entity access in Twig / PHP

Because the addon casts the stored value to a PHP boolean, plain truthiness checks are the idiomatic pattern — you rarely need presenter helpers:

{# Twig #}
{% if entry.is_active %}
  <span class="badge">Active</span>
{% endif %}

{{ entry.is_active ? 'on' : 'off' }}
// PHP
$isActive = $article->is_active; // true|false

Querying flagged records

The DB stores 1/0, so filter with explicit integers when using query builders — do not assume a boolean literal will be coerced:

$articles = $articles->where('is_active', 1)->get();

In Streams repository terms:

$posts->where('is_published', true)->get();

Toggling in forms / admin actions

The input view renders a switch. If you need to toggle from a custom controller, just write the boolean straight through the repository or model — the field type does not do anything exotic on save:

$article->is_featured = !$article->is_featured;
$article->save();

Extending behaviour

Want extra helpers like ->isOn() / ->isOff() on the presenter? Bind your own presenter by extending BooleanFieldType in your addon and overriding $presenter — this is the intended extension point. You can also override $inputView to swap the toggle for a styled switch.

Seeding

Boolean fields default cleanly in seeders/factories; just pass true/false:

Article::create(['title' => 'Example', 'is_published' => true]);

Validation

Boolean fields pair naturally with Laravel's boolean rule:

$request->validate(['is_published' => 'boolean']);

Gotchas and Tips

  • No standalone usage. This package is useless outside a Streams install. If you're not on PyroCMS/Streams, do not reach for it — use a plain Laravel boolean cast instead.
  • Tri-state nulls. If the column is nullable, a Boolean field can be null distinct from false. A raw {% if entry.flag %} treats null as falsy. Decide deliberately whether to allow nulls (e.g., "unknown" consent) or mark the field required with a default.
  • Checkbox / hidden-input pattern. HTML checkboxes don't post when unchecked. The input view typically emits a hidden <input value="0"> before the checkbox to force a 0 on save. If you fork the view, keep that ordering or "turn off" will silently do nothing.
  • Stored as tinyint(1), not native boolean. MySQL BOOLEAN is an alias for TINYINT(1). When writing raw SQL or migrations manually, use tinyint/boolean, and query with 1/0 if the query builder doesn't coerce types for you.
  • Reinstall after changes. Editing config/config.php or the input view inside the vendor addon requires php artisan addon:reinstall anomaly/boolean-field_type, and often a php artisan view:clear — Streams caches compiled addon views and the field type registry.
  • Field type slug is fixed. The registration slug is boolean, so migrations reference the string 'boolean'. Renaming the namespace or slug will break existing stream definitions.
  • Admin UI hides it well. The toggle appears under the field type list as a switch-style control; if it isn't there, the addon isn't installed/registered — check php artisan addon:list.
  • Low adoption. Two stars and no dependents means you're effectively on your own for bug reports. It's MIT and small, so read the source (it's a handful of files) and vendor a copy if you need tweaks rather than relying on upstream fixes.
  • Version pinning. Streams addons are tightly coupled to the Streams major version; pin anomaly/boolean-field_type to a version compatible with your anomaly/streams-platform rather than letting composer float it.
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.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core