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.
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.dist/; if the README mentions assets, run php artisan nova:publish once after install.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'),
];
}
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.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).->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.->hideFromIndex(), ->help('Raw bytes are stored on the model'), or ->rules('numeric') if you do expose it on forms.->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.Number::fileSize() or a Blade helper in custom tools) keeps KB/MB/GB presentation consistent across your admin panel.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.1.0.2; otherwise ^1.0.3 is a safe drop-in. There were no API or breaking changes in this release."2.4 MB" as a string, this field adds nothing — fix the storage first, or format on the way out yourself.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.Text field plus Number::fileSize(). Avoid spreading assumptions about its API across many resources.How can I help you explore Laravel packages today?