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.
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
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
src/BooleanFieldTypeServiceProvider.php — confirms the field type slug (boolean) and input view namespace.src/BooleanFieldType.php — the config schema, input view, and any cast logic.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 %}
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.
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
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();
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();
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.
Boolean fields default cleanly in seeders/factories; just pass true/false:
Article::create(['title' => 'Example', 'is_published' => true]);
Boolean fields pair naturally with Laravel's boolean rule:
$request->validate(['is_published' => 'boolean']);
boolean cast instead.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.<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.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.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.boolean, so migrations reference the string 'boolean'. Renaming the namespace or slug will break existing stream definitions.php artisan addon:list.anomaly/boolean-field_type to a version compatible with your anomaly/streams-platform rather than letting composer float it.How can I help you explore Laravel packages today?