treestoneit/text-wrap
A PHP text-wrapping utility for Laravel that breaks long strings into fixed-width lines. Wrap plain text or HTML safely, preserve whole words, and control line length for emails, reports, consoles, and any output where clean, readable formatting matters.
The first step is not installing — it is confirming what you actually have. The package listing and the description.md describe a dependency-free PHP string-wrapping utility ("break long strings at a configurable width, multibyte safe, one call returns the wrapped string"), while the code and prior assessments describe a Laravel Nova field (Text subclass + service provider + compiled Vue asset) that renders long values wrapped instead of truncated in index/detail views. Those are different packages with different integration stories. Resolve that before you write a single line of code.
Read the repo in this order:
composer.json — check require for laravel/nova and the PHP constraint, and look at extra.laravel.providers for auto-discovery. A laravel/nova: ^1.0 constraint tells you the field reading is correct and your Nova version is the blocker.src/ — if there is a class extending Laravel\Nova\Fields\Text, it is a Nova field. Note the exact namespace and class name; every example you find online (including the ones below) is a guess until you confirm it. If instead there is a static helper class with a wrap()-style method, it is a utility and the Nova instructions do not apply.Nova::script(...) / Nova::style(...) and any publishes(...) tag. This is what makes the field render.resources/js/field.js and dist/js/field.js — confirm whether only the compiled bundle shipped, and grep for v-html before trusting it in an admin panel.Install:
composer require treestoneit/text-wrap
If auto-discovery does not fire, register the provider in config/app.php. If the provider publishes assets, run its tag:
php artisan vendor:publish --tag=text-wrap
First use case (Nova field reading): replace a truncating Text field on an index view where operators need to read notes, addresses, or error payloads in full.
// Verify namespace/class in src/ before using.
use TreeStoneIT\TextWrap\TextWrap;
public function fields(Request $request)
{
return [
TextWrap::make('Notes')->onlyOnIndex(),
];
}
Before any of that, run the one-day spike: stock Text with a display callback plus a CSS override in your Nova theme. If it passes, you are done and you never add the dependency.
use Laravel\Nova\Fields\Text;
Text::make('Notes', 'notes')
->displayUsing(fn ($value) => $value)
->onlyOnIndex();
First use case (utility reading): wrap fixed-width output, e.g. a plain-text report or console table, at a set width and verify multibyte behaviour with real UTF-8 data before trusting it.
Use it as a display-only field, never as the edit affordance. The daily pattern is to separate forms from read views: a normal Textarea on forms, the wrapped field on index and detail.
use Laravel\Nova\Fields\Textarea;
TextWrap::make('Notes')->onlyOnIndex()->exceptOnForms(),
TextWrap::make('Notes')->onlyOnDetail(),
Textarea::make('Notes')->onlyOnForms()->alwaysShow(),
Keep the construction in one place. Because you will almost certainly swap the implementation later (theme CSS, displayUsing, or an in-repo field), centralise field creation so resource classes never change:
private function wrappedNotes(): TextWrap
{
return TextWrap::make('Notes')
->onlyOnIndex()
->help('Long text is wrapped for readability.');
}
Keep the public shape (TextWrap::make(...) plus standard Nova modifiers like sortable(), rules(), onlyOnIndex()) stable across whatever replaces it.
Vendor it, do not require it from Packagist. Since the package is archived, treat adoption as forking. Put it under a local path and own the code:
{
"repositories": [{ "type": "path", "url": "nova-components/text-wrap" }],
"require": { "treestoneit/text-wrap": "*" }
}
Then rebuild the Vue component against your installed Nova toolchain rather than shipping the 2018 bundle. Pin the commit; otherwise a future composer update can pull the abandoned release back in.
Prefer the CSS route when the requirement is purely visual. Wrapping width in the Nova index table is a theme concern (white-space, word-break, max-width on the cell), not a package setting. A handful of selectors in your Nova theme's CSS is often the whole fix.
If you end up building it yourself, php artisan nova:field vendor/text-wrap gets you the same skeleton (PHP field class, provider, Vue component) in an afternoon and puts the upgrade path under your control.
Test the render, not just the resolution. A PHPUnit test that boots a resource and asserts the field resolves will pass while the UI is blank — the common failure is asset-pipeline drift, not an exception. Add a browser smoke test or an explicit manual QA step confirming the cell shows wrapped text.
laravel/nova constraint. Do not force-install past the resolver; a conflict is doing you a favour.Nova::script()/Nova::style(), that dist/js/field.js exists at the registered path, and that you published assets. Then clear Laravel and Nova caches and republish.v-html and innerHTML; if user-controlled values are interpolated raw, switch to escaped interpolation. An archived admin field is an unattractive thing to explain in an incident review.$component string. Namespaces and component identifiers get renamed between forks and minor releases; use what is in src/, not what a blog post says.composer update.displayUsing() or a theme override, and treat this repo as a reference implementation to read for structure — not a dependency to add.How can I help you explore Laravel packages today?