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

App Util Laravel Package

carloschininin/app-util

Laravel utility helpers for building apps: handy functions, common traits, and small components to speed up development and reduce boilerplate. Lightweight package you can drop into projects for everyday tasks and consistent utilities.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require carloschininin/app-util:^0.2.0
    

    Add to config/app.php under providers:

    CarlosChininin\AppUtil\AppUtilServiceProvider::class,
    
  2. First Use Case: Helper Functions The package now supports Symfony 8.0 compatibility. Test the updated Helper facade:

    use CarlosChininin\AppUtil\Facades\Helper;
    
    // Example: Generate a random string (works with Symfony 8.0)
    $randomString = Helper::randomString(10);
    dd($randomString); // Outputs a 10-character alphanumeric string
    
  3. Key Facades (Unchanged)

    • Helper – General utilities (strings, arrays, etc.)
    • ResponseHelper – HTTP response helpers
    • FileHelper – File operations

Implementation Patterns

1. String and Array Manipulation (Updated for Symfony 8.0)

Pattern: Replace Laravel’s Str and Arr helpers with Helper for consistency.

// Works seamlessly with Symfony 8.0 components
$slug = Helper::slug('Hello World!');

// Symfony 8.0 compatible array operations
$values = Helper::pluck($array, 'key');

2. HTTP Response Shortcuts (Symfony 8.0 Compatible)

Pattern: Use ResponseHelper for API responses.

use CarlosChininin\AppUtil\Facades\ResponseHelper;

return ResponseHelper::success($data, 'Operation completed');
// Returns: { "success": true, "data": [...], "message": "Operation completed" }

3. File Operations (Symfony 8.0 Integration)

Pattern: Centralize file handling with Symfony 8.0 filesystem components.

use CarlosChininin\AppUtil\Facades\FileHelper;

// Upload a file (now supports Symfony 8.0 filesystem)
$path = FileHelper::upload('file.jpg', 'uploads/');

// Generate a download URL (Symfony 8.0 compatible)
$url = FileHelper::generateDownloadUrl($path);

4. Middleware Integration (Symfony 8.0 Request Handling)

Pattern: Use Helper::ip() or Helper::userAgent() in middleware.

public function handle($request, Closure $next) {
    $ip = Helper::ip($request); // Works with Symfony 8.0 RequestStack
    $request->merge(['user_ip' => $ip]);
    return $next($request);
}

5. Customizing Responses (Symfony 8.0 Response Factory)

Pattern: Extend ResponseHelper with Symfony 8.0 ResponseFactory.

php artisan vendor:publish --provider="CarlosChininin\AppUtil\AppUtilServiceProvider"

Modify config/app-util.php to integrate Symfony 8.0 response formats:

'response' => [
    'factory' => \Symfony\Component\HttpFoundation\ResponseFactory::class,
],

Gotchas and Tips

Pitfalls

  1. Symfony 8.0 Dependency Conflicts

    • If using Symfony 8.0 components elsewhere, ensure version compatibility:
      composer require symfony/http-foundation:^6.3
      
    • Avoid mixing Symfony 6.x and 8.x components in the same project.
  2. Facade Caching (Symfony 8.0 Service Container)

    • Facades now integrate with Symfony 8.0 service container. Clear cache if modifying behavior:
      php artisan config:clear
      php artisan cache:clear
      
  3. File Path Assumptions (Symfony 8.0 Filesystem)

    • FileHelper now defaults to Symfony 8.0 Filesystem. Override in config:
      'file' => [
          'adapter' => 'local', // 'local', 's3', or custom
          'symfony_version' => '8.0',
      ],
      
  4. Random String Collisions (Symfony 8.0 Random Generator)

    • Helper::randomString() now uses Symfony 8.0's Random component. For cryptographic needs, use:
      use Symfony\Component\Uid\Uuid;
      $uuid = Uuid::v4();
      

Debugging

  • Symfony 8.0 Debugging Enable debug mode in config/app-util.php:

    'debug' => env('APP_DEBUG', false),
    

    Logs facade calls to storage/logs/app-util.log with Symfony 8.0 stack traces.

  • Check Published Config Ensure config/app-util.php matches Symfony 8.0 expectations after publishing:

    php artisan vendor:publish --provider="CarlosChininin\AppUtil\AppUtilServiceProvider"
    

Extension Points

  1. Add Custom Helpers (Symfony 8.0 Service Integration) Bind new helpers in AppServiceProvider with Symfony 8.0 services:

    Helper::extend('custom', function ($input) {
        return strtoupper($input);
    });
    

    Usage:

    Helper::custom('hello'); // "HELLO"
    
  2. Override Response Templates (Symfony 8.0 Response) Extend ResponseHelper with Symfony 8.0 Response:

    ResponseHelper::macro('customResponse', function ($data) {
        return new \Symfony\Component\HttpFoundation\JsonResponse(['custom' => $data]);
    });
    
  3. File Helper Events (Symfony 8.0 EventDispatcher) Listen for file operations via Symfony 8.0 events (publish events first):

    php artisan vendor:publish --tag="app-util-events"
    

    Example listener with Symfony 8.0 EventDispatcher:

    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    use CarlosChininin\AppUtil\Events\FileUploaded;
    
    class FileUploadSubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                FileUploaded::class => 'onFileUploaded',
            ];
        }
    
        public function onFileUploaded(FileUploaded $event)
        {
            Log::info('File uploaded:', ['path' => $event->path]);
        }
    }
    
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor