visiosoft/json-field_type
Visiosoft JSON Field Type provides a custom field type for Laravel/Streams applications to store and edit JSON data through standard admin forms. It integrates structured JSON input into existing field workflows, making it easy to manage configuration or metadata without custom UI code.
composer.json first:composer require visiosoft/json-field_type
If the addon is not auto-discovered, install/register it through your PyroCMS addon workflow, e.g. php artisan addon:install visiosoft.field_type.json, or place it under your addons path.
src/JsonFieldType.php, resources/views/, composer.json, and the README. The class name typically determines the field type slug: JsonFieldType becomes json.// Migration: prefer native json where supported, otherwise text
Schema::table('example_widgets', function (Blueprint $table) {
$table->json('settings')->nullable(); // or $table->text('settings')->nullable()
});
// Stream definition
$stream->addField('settings', 'json', [
'required' => false,
]);
Then edit the field in the control panel and read it from code/templates. Check whether the field type returns a raw JSON string or a decoded value before writing consumers.
public function getSettingsAttribute($value)
{
return json_decode($value, true) ?: [];
}
Then in Twig:
{{ entry.settings.theme|default('light') }}
protected $casts = ['settings' => 'array'];
Be careful with PyroCMS entry fields; if casting conflicts with Streams attributes, use a presenter or accessor instead.
nullable with Laravel's json rule and normalize empty strings to null before validation:$stream->addField('settings', 'json', [
'rules' => ['nullable', 'json'],
]);
whereJsonContains() or settings->theme only when the database column is actually a native json type. For text columns, either query with LIKE sparingly or promote frequently filtered keys to real columns.json_encode($value), never a PHP array. Encode with JSON_THROW_ON_ERROR in your import scripts so bad data fails early.json. If the class slug conflicts, rename or namespace your own field type.'', null, '{}', and '[]' behave differently. Normalize empty input to null, and do not let an empty string reach a native json column.json columns reject invalid JSON at the database level; text columns accept anything. Prefer json where MySQL/PostgreSQL supports it.|raw; when embedding into JavaScript, use json_encode.php artisan streams:compile
php artisan cache:clear
$entry->getAttributes()['settings'], to determine whether the package returns a string or decoded array. This drives whether you need an accessor.$inputView, $rules, or getValue() in a subclass; override views only if the package supports publishing them. Keep patches out of vendor/ so upgrades or removal remain possible.How can I help you explore Laravel packages today?