laragraph/utils
Laravel utilities for building GraphQL servers: shared primitives and helpers used by GraphQL packages. Install via Composer and use as a lightweight foundation for SDL-first (Lighthouse) or code-first (graphql-laravel) setups.
Start by requiring the package via Composer: composer require laragraph/utils. No service provider or config file is needed—it’s designed to be auto-discovered via PHP’s function autoloading. The package ships with a small, curated set of globally available helper functions (e.g., str_starts_with_any(), array_pull_first(), array_dot_pluck()) and a few lightweight trait-based utilities. Your first use case should be replacing ad-hoc string/array logic in controllers or services—look for patterns like manual explode()/join() chains or repetitive null-coalescing. For example, replace isset($data['key']) ? $data['key'] : 'default' with Arr::get($data, 'key', 'default') if the Arr helper is included, or use the provided data_get_default() if available. Check the src/helpers.php file for a full list of exported functions—they’re namespaced-friendly and won’t conflict with Laravel’s existing helpers.
str_between($haystack, $start, $end) to extract substrings cleanly, or arr_filter_nulls() to sanitize request data before validation.array_flat_pluck() for nested array extraction or array_group_with_key() to build associative groupings without verbose loops.str_slug_safe() to generate URL slugs while ensuring uniqueness without custom validation logic.HasUniqueSlug to models to inject shared slug generation and validation logic, avoiding duplication across models.Validation::emailOrUtmSource()) to centralize and standardize input rules across controllers.composer.json’s files autoloading, avoid using them inside config files—they won’t be available during config:cache.\laragraph\utils\ fully qualified namespace when ambiguous.app/Support/helpers.php, and list it in composer.json under autoload.files after laragraph/utils to ensure precedence.How can I help you explore Laravel packages today?