Download the PHP package ca-santos/laravel-support without Composer
On this page you can find all versions of the php package ca-santos/laravel-support. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-support
Laravel Support
A collection of small, dependency-light helpers for things almost every Laravel
project ends up writing by hand: string/array/date/number formatting, casting
request-style input, safe redirects, money and enum utilities, building
Eloquent eager-load constraints, generating migrations at runtime, and
hydrating plain PHP objects from arrays (including nested objects, Carbon
dates, Collections and enums).
Everything is a plain static call — no service container bindings, no
facades to fake in tests, no configuration to publish. This package only adds
what Laravel doesn't already give you: nothing here duplicates a native
Str, Arr, Number, or Eloquent method — where one already exists, use it
directly instead.
Table of contents
- Requirements
- Installation
- How this package is organized
- Helpers
StringHelperArrayHelperObjectHelperDateHelperNumberHelperMoneyHelperValueHelperValidationHelperHtmlHelperFileHelperUrlHelperEnumHelperCollectionHelperEloquentHelperSchemaHelperSqlHelperLaravelHelperCacheHelperLabelHelperSseHelper
- Object hydration
- Model traits (
HasSlug,HasMetadata) InteractsWithEnum- Makeable objects (
IsMakeable,Component) - Runtime migration generation
- Optional dependencies
- Testing & code quality
- Security
- License
Requirements
- PHP 8.2+
illuminate/support9.x through 12.x (works with Laravel 9 through 12)
Installation
The service provider (CaueSantos\Support\ServiceProvider) is auto-discovered
by Laravel — there is nothing to register or publish.
How this package is organized
Every class named XyzHelper lives under CaueSantos\Support\Helpers and
exposes only public static methods — use the class and call it, nothing
to instantiate:
A handful of classes live directly under CaueSantos\Support because they
aren't stateless utility helpers — traits meant to be used on your own
classes, small value objects, or tools with their own constructor/state
(object hydration, migration generation). Those are documented in their own
sections below.
StringHelper
CaueSantos\Support\Helpers\StringHelper — string generation and formatting
that Laravel's own Str class doesn't cover.
Need to replace only the first occurrence of a substring, or slugify a string for a URL? Use Laravel's own
Str::replaceFirst()/Str::slug()directly — this package used to wrap both, but they're already exactly what you need with no difference in behavior.
ArrayHelper
CaueSantos\Support\Helpers\ArrayHelper — recursive array transforms,
plucking, key renaming, and tree building.
isListOfArrays()looks similar to Laravel's nativeArr::isList()but checks something different:Arr::isList()only cares whether the keys are sequential, whileisListOfArrays()additionally requires at least one element to itself be an array.
modifyRecursive(), mapRecursive(), buildPathArrays() and
pluckGrouped() cover tree/menu-shaped data — see their docblocks in
src/Helpers/ArrayHelper.php for the exact shape each one expects and
returns (buildPathArrays() in particular returns one flattened list of
every leaf's path segments, not one path-array per leaf — check its
docblock before relying on the shape).
ObjectHelper
CaueSantos\Support\Helpers\ObjectHelper — deep array ⇄ stdClass
conversion via a JSON round-trip.
DateHelper
CaueSantos\Support\Helpers\DateHelper — date validation/formatting and
minute-to-hour formatting.
isValidDate()isn't the same as Carbon's ownCarbon::hasFormat():hasFormat()only checks that a string matches a format's shape — it actually returnstrueforCarbon::hasFormat('2024-02-30', 'Y-m-d'), an impossible date.isValidDate()round-trips the value back through the same format and rejects it if it doesn't match exactly, so it correctly returnsfalsethere.For "now, in a given timezone", just use Laravel's own
now('UTC')— no helper needed.
NumberHelper
CaueSantos\Support\Helpers\NumberHelper — byte formatting, memory usage,
lightweight id generation, and clamping.
Laravel's own
Number::fileSize()(Illuminate\Support\Number) looks similar but always pads to the given precision (Number::fileSize(1536, precision: 2)->"1.50 KB"), whereformatBytes()trims trailing zeros ("1.5 KB"). Pick whichever output style you want — they're genuinely different, not interchangeable.
MoneyHelper
CaueSantos\Support\Helpers\MoneyHelper — rounding-safe, cents-based money
conversion and arithmetic. For currency formatting (symbols, locales), use
Laravel's own Number::currency() instead — this class only covers what
that doesn't: safe integer arithmetic.
ValueHelper
CaueSantos\Support\Helpers\ValueHelper — emptiness checks and
instance-of checks that read better than nested ternaries.
ValidationHelper
CaueSantos\Support\Helpers\ValidationHelper — the one thing Laravel
doesn't already give you a one-liner for: namespacing attributes for
"each row of this array" validation rules.
To build a
ValidationExceptionfrom a plainattribute => message(s)array, just call Laravel's own\Illuminate\Validation\ValidationException::withMessages($errors)directly — it already accepts exactly that shape, no wrapper needed.
HtmlHelper
CaueSantos\Support\Helpers\HtmlHelper — small HTML-generation utilities.
FileHelper
CaueSantos\Support\Helpers\FileHelper — temp files, zip/unzip, CSV
generation, MIME labels.
UrlHelper
CaueSantos\Support\Helpers\UrlHelper — external-vs-internal URL detection
and open-redirect protection. Laravel doesn't ship anything for this out of
the box.
EnumHelper
CaueSantos\Support\Helpers\EnumHelper — utilities for any PHP 8.1+ enum
(backed or pure).
See also InteractsWithEnum to add these as methods
directly on the enum itself.
CollectionHelper
CaueSantos\Support\Helpers\CollectionHelper — building nested Laravel
Collections that support both array and object-style access.
EloquentHelper
CaueSantos\Support\Helpers\EloquentHelper — relation-loaded checks, model
mapping, and closures for Eloquent's constrained eager loading.
SchemaHelper
CaueSantos\Support\Helpers\SchemaHelper — schema introspection, DDL
helpers and SQL fragment building.
dropColumnIfExists() is portable across every driver Laravel supports
(MySQL, MariaDB, Postgres, SQLite, SQL Server). The foreign-key methods are
portable on Laravel 11+ (via Schema::getForeignKeys()), with a
MySQL/MariaDB-only fallback on older versions — note that SQLite's foreign
keys have no constraint name at all, so they can be detected but not
dropped there. canBeHistorical() stays MariaDB-only: system versioning
has no equivalent in MySQL, Postgres or SQL Server.
SqlHelper
CaueSantos\Support\Helpers\SqlHelper — parsing and analyzing raw SQL
strings. Requires greenlion/php-sql-parser (see
Optional dependencies).
LaravelHelper
CaueSantos\Support\Helpers\LaravelHelper — small, one-off framework
integrations that don't warrant their own class.
CacheHelper
CaueSantos\Support\Helpers\CacheHelper — a cache-stampede-safe
remember(). Requires a cache store that supports atomic locks (redis,
memcached, database, dynamodb, or the array store).
Looking for a "serve stale data while refreshing in the background" strategy instead of blocking? That's Laravel's own
Cache::flexible()— a different trade-off, not a replacement for this.
LabelHelper
CaueSantos\Support\Helpers\LabelHelper — tiny display-label formatting.
SseHelper
CaueSantos\Support\Helpers\SseHelper — a minimal Server-Sent Events
response helper.
Object hydration
Two traits and one static class work together to fill a plain PHP object's
typed properties from an array — casting scalars to their declared type,
parsing dates into Carbon, resolving enums, building nested Collections,
and recursively hydrating nested typed objects.
IsHydratable—usethis on any class to get::hydrate($data)(new instance),::hydrateNoConstructor($data)(skips your__construct(), useful when it has required arguments), and->hydrateCurrent($data)(hydrate an already-built instance in place). Accepts an array, anArrayAccessimplementation, or astdClass(e.g. straight fromjson_decode()).AutoJsonSerializable— addsjsonSerialize(): array, reflecting over every non-static public/protected/private property (recursing into nested objects, unwrapping enum values). To havejson_encode($person)call it automatically, alsoimplements \JsonSerializableon the class; otherwise call$person->jsonSerialize()directly. OverrideserializeWith()to merge in computed keys that aren't backed by a real property.ClassHydrator— the static engine both traits delegate to.ClassHydrator::hydrate($existingInstance, $data)— hydrate an object you didn't build throughIsHydratable.ClassHydrator::hydrateMany(Person::class, $rows)— hydrate a list of arrays into aCollectionofPersoninstances in one call.ClassHydrator::dehydrate($person)— the reverse of hydration: a plain array back out of a hydrated object (enums unwrapped to their value, dates formatted as ISO-8601 strings, nested objects/Collections recursed into), without going through a JSON round-trip likeAutoJsonSerializabledoes.
ClassPropertyHelper— the lower-level type-coercion primitives (toBoolean(),toInteger(),convertValue(), ...)ClassHydratoris built on. Most consumers won't need to call it directly.
Model traits (HasSlug, HasMetadata)
HasSlug auto-generates a slug column from another attribute when a
model is created, appending -2, -3, etc. if it would otherwise collide:
HasMetadata gives a model a flexible, dot-notation-aware key-value
store backed by a single JSON column (default: meta — cast it to array):
InteractsWithEnum
use on a backed or pure enum to add a default label() derived from the
case name, plus options()/values()/names() static passthroughs to
EnumHelper. Override label() on the enum itself for
custom per-case labels.
Makeable objects (IsMakeable, Component)
IsMakeable is a one-method trait: use it on any class to get a
::make(...$arguments) static constructor that just forwards to new static(...$arguments) — handy for a fluent, static-friendly construction
style.
Component is a tiny, ready-made value object built on IsMakeable for
describing a named UI component with its data — e.g. handing a Blade/Inertia
component name and props around as a single value:
Runtime migration generation
RuntimeMigration builds a real Laravel migration file (not a
migration run in-process) from a Blueprint closure, so you can generate
migrations programmatically — e.g. from a schema-builder UI, an artisan
command, or a code generator.
If the target directory doesn't exist, or the file can't be written,
create()/update() throw CaueSantos\Support\Exceptions\MigrationGenerationException.
Two smaller pieces support this:
Stub— a minimal{{ placeholder }}template renderer used to fill in the bundledstubs/migration.create.stubandstubs/migration.update.stubtemplates.Stub::create($path, ['table' => 'posts'])->render().HistoricalDataMigration— wraps MariaDB's system-versioning (ADD SYSTEM VERSIONING) DDL so an "update" migration generated byRuntimeMigrationcan safely alter a historical/versioned table. MariaDB only.
Optional dependencies
Two methods need a package this library doesn't force on every consumer —
both are declared under Composer's suggest, not require, so install them
only if you actually call the method that needs them:
| Package | Needed for |
|---|---|
greenlion/php-sql-parser |
SqlHelper::getExpressionByAlias() |
inertiajs/inertia-laravel |
LaravelHelper::forceInertiaRedirect() |
Testing & code quality
All three run in CI on every push and pull request, across a PHP 8.2–8.4
matrix (see .github/workflows/).
Security
If you discover any security related issues, please email instead of using the issue tracker.
License
MIT. See LICENSE.