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

Nova File Size Field Laravel Package

itiden/nova-file-size-field

A simple Laravel Nova field that displays file sizes in a human-readable format. Drop it into your resource to automatically convert raw byte values into KB, MB or GB, keeping index and detail views clean and easy to scan.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install with composer require itiden/nova-file-size-field. This package is a Laravel Nova custom field, so a working Nova installation (a paid, private package) is a hard prerequisite. If you don't already have Nova wired up, this field is not usable on its own.
  • There is no service provider or config to publish for typical use — Nova auto-discovers fields via their class. Some Nova fields ship compiled assets in dist/; if the README mentions assets, run php artisan nova:publish once after install.
  • First use case: add it to a Nova resource's fields() method for a column that stores a raw byte count, e.g. an attachments.size or files.bytes integer column:
    use Itiden\NovaFileSizeField\FileSize;
    
    public function fields(NovaRequest $request)
    {
        return [
            FileSize::make('Size', 'size'),
        ];
    }
    
  • Look first at: (1) the README for the exact make() signature and any formatter options, (2) the single field class under src/ — this is a small package, so reading the ~100 lines of PHP is faster than guessing behavior, and (3) whether the field renders on index/detail only or also on forms.

Implementation Patterns

  • Read-only display field. This is a presentation layer over a numeric column. Use it in fields() on resources where the underlying attribute is bytes (integers). Pair it with ->onlyOnIndex() / ->onlyOnDetail() if it shouldn't appear on create/update forms (a byte count is rarely something you type by hand).
  • Sorting. If the DB column is a real numeric column, ->sortable() will sort correctly by bytes. Do not expect sorting to work on a computed/accessor value unless the field supports a sortable callback — verify against the source before relying on it.
  • Combine with Nova's standard modifiers, e.g. ->hideFromIndex(), ->help('Raw bytes are stored on the model'), or ->rules('numeric') if you do expose it on forms.
  • Computed sizes. If you want to show a size that isn't a plain column (e.g. total disk usage), compute it via an accessor on the model or a ->resolveUsing()-style callback if the field supports one, then point the field at that attribute. Keep the raw bytes available on the model so the field still has something numeric to format.
  • Consistency across resources. Because the formatting lives in the field, using it everywhere (rather than hand-formatting with Number::fileSize() or a Blade helper in custom tools) keeps KB/MB/GB presentation consistent across your admin panel.

Gotchas and Tips

  • Nova version compatibility is the real risk. Nova's field API changed between major versions (v4 → v5). A 1.0.x release that only tweaks PHP compatibility tells you nothing about Nova version support — confirm the supported Nova major in composer.json (nova constraint) before upgrading in a project on the latest Nova.
  • PHP 8.1 requirement (from 1.0.3). The 1.0.3 change is a PHP 8.1 compatibility fix. If any part of your stack is pinned below 8.1, stay on 1.0.2; otherwise ^1.0.3 is a safe drop-in. There were no API or breaking changes in this release.
  • Bytes, not strings. The field expects a numeric value. If your column already stores "2.4 MB" as a string, this field adds nothing — fix the storage first, or format on the way out yourself.
  • Units and localization. Check whether the field emits decimal (KB, MB) or binary (KiB, MiB) units and whether it localizes the decimal separator. If your reporting needs a specific convention, subclass the field and override the formatting rather than patching vendor code.
  • Small-maintainer dependency. This is a tiny, low-traffic package (1.0.3, first-time contributor). It's cheap insurance to read the whole field class — if upstream ever stalls, you can vendor/copy it or replace it with a one-line Nova Text field plus Number::fileSize(). Avoid spreading assumptions about its API across many resources.
  • Debugging display issues is almost always one of: wrong column name, non-numeric value in the column, or stale published assets after a Nova upgrade — clear the Nova asset cache / re-publish before digging into the PHP.
  • Extension point: subclassing the field (or overriding its formatting method, if exposed) is the clean way to customize; treat the package as a formatting primitive rather than a feature-rich field.
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.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource