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

Common Laravel Package

dontdrinkandroot/common

A small utility library with commonly used PHP helpers and extensions, including a PHPStan extension. Intended to provide shared building blocks for projects, with CI and code quality tooling support via SonarCloud badges.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require dontdrinkandroot/common
    

    Register the service provider in config/app.php:

    'providers' => [
        // ...
        DontDrinkAndRoot\Common\CommonServiceProvider::class,
    ],
    
  2. First Use Case Use the Helper facade for quick utilities:

    use DontDrinkAndRoot\Common\Facades\Helper;
    
    // Example: Generate a UUID
    $uuid = Helper::uuid();
    
  3. Key Entry Points

    • Facade: Helper (for most utilities)
    • Traits: HasCommon (for reusable methods in classes)
    • Standalone Functions: dontdrinkandroot\common\helpers\* (if not exposed via facade)

Implementation Patterns

Common Workflows

  1. Data Validation & Sanitization Use Helper::sanitizeInput() or Helper::validateEmail() in controllers/forms:

    $cleanedInput = Helper::sanitizeInput($request->all(), ['field' => 'string']);
    
  2. File & Path Handling Leverage Helper::path() or Helper::fileExists() in service classes:

    if (Helper::fileExists($filePath)) {
        $content = Helper::fileGetContents($filePath);
    }
    
  3. Date/Time Utilities Format dates consistently:

    $formattedDate = Helper::formatDate($date, 'Y-m-d H:i:s');
    
  4. Array Manipulation Use Helper::arrayPluck() or Helper::arrayMergeRecursive():

    $plucked = Helper::arrayPluck($collection, 'key');
    
  5. Security Helpers Hash passwords or generate secure tokens:

    $hashed = Helper::hash('password');
    $token = Helper::generateToken();
    

Integration Tips

  • Laravel Blade: Extend Blade directives for reusable components:

    Blade::directive('uuid', function () {
        return "<?php echo DontDrinkAndRoot\Common\Facades\Helper::uuid(); ?>";
    });
    

    Usage: @uuid in views.

  • Service Layer: Inject Helper into services for reusable logic:

    public function __construct(private Helper $helper) {}
    
  • Middleware: Use Helper::ip() or Helper::userAgent() for request metadata:

    $ip = Helper::ip();
    

Gotchas and Tips

Pitfalls

  1. Facade vs. Direct Calls

    • Some methods may not be exposed via the Helper facade. Check the helpers directory for standalone functions.
    • Example: dontdrinkandroot\common\helpers\StringHelper::camelCase() may not be facaded.
  2. Namespace Conflicts

    • The package uses dontdrinkandroot\common namespace. Ensure no naming collisions with your project’s classes.
  3. Configuration Overrides

    • Some helpers (e.g., Helper::uuid()) may rely on default configurations. Override via:
      config(['common.uuid_version' => 4]);
      
  4. Deprecation Warnings

    • The package is new (0 stars, last release 2024-04-16). Monitor for breaking changes in minor updates.

Debugging Tips

  • Log Helper Outputs Use Helper::log() for debugging:

    Helper::log('Debug message', 'debug');
    
  • Check for Null Returns Some helpers (e.g., Helper::fileGetContents()) return false on failure. Validate:

    $content = Helper::fileGetContents($path);
    if ($content === false) {
        // Handle error
    }
    

Extension Points

  1. Custom Helpers Extend the Helper facade by publishing config:

    php artisan vendor:publish --provider="DontDrinkAndRoot\Common\CommonServiceProvider" --tag="config"
    

    Add your methods to config/common.php under helpers.

  2. Traits for Reusability Use HasCommon trait in models/services:

    use DontDrinkAndRoot\Common\Traits\HasCommon;
    
    class MyModel {
        use HasCommon;
        // Now has access to all helper methods
    }
    
  3. Override Default Behavior Bind custom implementations to the container:

    $this->app->bind('dontdrinkandroot\common\helpers\StringHelper', function () {
        return new CustomStringHelper();
    });
    

Performance Notes

  • Avoid Heavy Operations in Facades Offload complex logic to services to prevent facade bloat.
  • Cache Repeated Calls Use Laravel’s cache for expensive helper operations:
    $data = Cache::remember('helper_key', 60, function () {
        return Helper::expensiveOperation();
    });
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui