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

Url Field Type Laravel Package

anomaly/url-field_type

Anomaly URL Field Type adds a URL field type for Laravel Streams, letting you capture, validate, and display website links in control panels and forms with a simple, focused input field.

View on GitHub
Deep Wiki
Context7

Getting Started

This addon registers a single field type, anomaly.field_type.url, for the PyroCMS/Streams platform. It is almost always pulled in transitively by pyrocms/pyrocms or anomaly/streams-platform, so a manual composer require anomaly/url-field_type is usually only needed on stripped-down installs.

Where to look first:

  • src/UrlFieldType.php — the field type class; this is where getInputView(), getRules(), and any presenter wiring live.
  • src/UrlFieldTypePresenter.php — if present, this is what $entry->my_field returns. Check whether it adds helpers like link()/path() or just returns the raw string.
  • resources/views/input.twig — the admin form markup (an <input type="url">).
  • resources/config/config.php — any tweakable validation rules or defaults.
  • resources/lang/en/addon.php — the name/description registered into the admin field type picker.

First use case: add a "Website" URL to an existing stream. In your migration/seed (or via the Streams admin UI → Fields → Add Field), set the field type to url. In the admin form builder this appears as a plain text input with browser-level URL validation; on save it stores a string column.

Minimal migration-style assignment:

$stream->addField('website', [
    'type'   => 'anomaly.field_type.url',
    'config' => [
        'default_value' => 'https://example.com',
    ],
]);

Implementation Patterns

Reading the value. The field is stored as a varchar/text column. Access it exactly like any other field:

{{ entry.website }}

If the field ships a presenter, $entry->website will be a UrlFieldTypePresenter in PHP, but when echoed in Twig it casts to the string. Guard against empty values — a URL field is frequently optional:

{% if entry.website %}
    <a href="{{ entry.website }}" rel="noopener" target="_blank">{{ entry.website }}</a>
{% endif %}

Composing with other field types. Pair this field with a text field for a human-readable label (e.g. website_label) rather than trying to derive one. The URL field type deliberately does not model a link object.

Validation. The addon typically adds the url rule (and sometimes active_url). If you need to accept relative paths, protocol-less values, or internal routes, don't fight the field type — add a custom rule via the field's config or override getRules() in a subclassed field type:

protected $rules = ['nullable', 'string', 'max:255'];

Presenter extension. If you need ->domain() or ->favicon(), extend UrlFieldTypePresenter in your own addon and register it through the field type's $presenter binding, rather than editing vendor code.

Form rendering in custom modules. If you're hand-rolling a form outside the Streams form builder, render the field's input view directly:

{{ form.fields.website.input|raw }}

Twig-safe output. Since the value is a user-supplied URL, always let Twig autoescape. Do not use |raw on the URL itself; only use |raw on the rendered input HTML in admin contexts.

Gotchas and Tips

  • It is a text field with a URL mask. Do not expect automatic scheme prefixing, normalization, or trimming of trailing slashes. If users type example.com, you will store example.com. Add a mutator or a saving hook on the entry if that matters to you.
  • No frontend rendering. The field type provides an admin input and a value; there is no default anchor view. Any target="_blank", rel="noopener", or favicon behavior is your responsibility.
  • Empty-string vs null. Streams often stores '' rather than null for blank optional fields. {% if entry.website %} handles both, but entry.website is null does not. Prefer truthiness checks.
  • Validation is strict. The default url rule rejects protocol-relative (//cdn.example.com) and relative (/contact) values. This bites when people reuse the field type for internal paths — use a text field for those, or loosen the rules.
  • Schema length. If your migration creates the column as VARCHAR(255) and someone pastes a signed URL, it truncates (or errors depending on MySQL mode). Use text for anything that may hold query strings.
  • Config quirks. config.php is merged at the addon level, not per-field, unless you override values in the field definition's config array. Field-level config wins; keep that in mind when debugging why a rule "isn't applying."
  • Admin-only assets. The input view loads in the control panel only; if you try to reuse the field's view on the frontend you'll usually get missing admin CSS/JS. Render your own markup on the frontend.
  • Debugging empty output. Check the raw value in the DB first (SELECT website FROM ...), then check whether a presenter is swallowing it. A common cause is a presenter method name matching the field name and returning null.
  • Version compatibility. This addon targets PyroCMS 3.x / Streams platform 1.x. On Laravel 9+/PyroCMS 4 forks, verify the service provider still registers under the expected namespace (Anomaly\UrlFieldType\UrlFieldTypeServiceProvider).
  • Extension points. The cleanest customizations are: subclassing UrlFieldType to change getRules()/getConfig(), overriding the presenter for helper methods, and publishing the input view to your own addon's resources/views to change the admin markup — in that order of preference.
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.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin