Weave Code
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

Helper Laravel Package

braunstetter/helper

braunstetter/helper is a small PHP/Laravel helper package that groups handy utility functions for everyday development—common string, array, and miscellaneous helpers you can reuse across projects to reduce boilerplate and speed up coding.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require braunstetter/helper
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        Braunstetter\Helper\HelperServiceProvider::class,
    ],
    
  2. First Use Case Use the Helper facade to access common utilities:

    use Braunstetter\Helper\Facades\Helper;
    
    // Generate a UUID
    $uuid = Helper::uuid();
    
    // Format a date
    $formatted = Helper::formatDate('2023-01-01', 'Y-m-d H:i:s');
    
    // Check if a string is sluggable
    $isSluggable = Helper::isSluggable('Hello World');
    
  3. Key Facade Methods

    • uuid() → Generate UUIDs.
    • formatDate() → Standardize date formatting.
    • isSluggable() → Validate slug-friendly strings.
    • arrayToObject() → Convert arrays to objects.
    • objectToArray() → Convert objects to arrays.
    • snakeCase()/camelCase() → String case conversion.

Implementation Patterns

Common Workflows

1. Data Transformation

// Convert API responses (arrays) to objects for Eloquent
$response = Helper::arrayToObject($apiData);
$user = User::create($response);

// Convert Eloquent models to arrays for API responses
$users = User::all()->toArray();
$serialized = Helper::objectToArray($users);

2. UUID Generation

// Generate UUIDs for database records
$record = [
    'id' => Helper::uuid(),
    'name' => 'Test',
    'created_at' => now(),
];

3. Slug Handling

// Validate and generate slugs
$title = "Hello World 2023";
$slug = Helper::slug($title); // "hello-world-2023"
if (Helper::isSluggable($title)) {
    // Proceed with slug logic
}

4. Date Standardization

// Normalize dates across the app
$createdAt = Helper::formatDate($user->created_at, 'Y-m-d H:i:s');
$displayDate = Helper::formatDate($createdAt, 'M d, Y');

Integration Tips

  • Service Layer: Use Helper in service classes to abstract repetitive logic.
  • Middleware: Validate slugs or format dates in middleware before processing requests.
  • Form Requests: Sanitize input strings (e.g., slugs) using isSluggable().
  • API Responses: Standardize date formats in responses using formatDate().

Gotchas and Tips

Pitfalls

  1. UUID Collisions

    • The package uses PHP’s ramsey/uuid under the hood. Ensure no duplicate UUIDs are generated in high-concurrency environments (unlikely but possible with custom UUID versions).
    • Fix: Use Helper::uuid()->toString() for explicit string conversion.
  2. Date Parsing Edge Cases

    • formatDate() may fail on invalid dates (e.g., "2023-02-30"). Always validate input dates first.
    • Fix: Use Carbon’s createFromFormat() or tryParse() before passing to formatDate().
  3. Case Conversion Quirks

    • snakeCase()/camelCase() may not handle Unicode or special characters as expected.
    • Fix: Pre-sanitize strings with preg_replace('/[^a-zA-Z0-9]/', ' ', $string).
  4. Object/Array Conversion

    • arrayToObject() creates stdClass objects by default. Nested arrays may not convert as expected.
    • Fix: Use json_decode(json_encode($array), FALSE) for deeper conversion or extend the helper.

Debugging Tips

  • Check Method Availability: Run php artisan tinker and dump Helper::methods() to see all available methods.
  • Log Helper Outputs: Debug UUIDs or formatted dates with:
    \Log::debug('Generated UUID:', ['uuid' => Helper::uuid()]);
    
  • Override Defaults: Publish the config (if available) or extend the helper:
    // app/Helpers/ExtendedHelper.php
    namespace App\Helpers;
    use Braunstetter\Helper\Facades\Helper as BaseHelper;
    
    class ExtendedHelper extends BaseHelper {
        public static function customSlug($string) {
            return parent::slug($string) . '-custom';
        }
    }
    

Extension Points

  1. Custom UUID Version Modify the service provider to bind a custom UUID generator:

    // app/Providers/AppServiceProvider.php
    public function register() {
        $this->app->bind(\Braunstetter\Helper\Contracts\UuidGenerator::class, function () {
            return new \Ramsey\Uuid\UuidFactory();
        });
    }
    
  2. Add New Methods Extend the Helper trait or create a decorator:

    // app/Traits/CustomHelper.php
    trait CustomHelper {
        public function pluralize($string) {
            return Helper::endsWith($string, 'y') ? rtrim($string, 'y') . 'ies' : $string . 's';
        }
    }
    
  3. Override Config If the package supports config, publish and extend it:

    php artisan vendor:publish --provider="Braunstetter\Helper\HelperServiceProvider"
    

    Then modify config/helper.php (if exists).

Performance Notes

  • UUID Generation: Caching UUIDs (e.g., in a trait) may improve performance for bulk operations.
  • Date Formatting: Reuse formatted dates in memory to avoid redundant parsing.
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle