Weave 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

Laravel Toolkit Laravel Package

ermradulsharma/laravel-toolkit

A lightweight Laravel toolkit bundling handy helpers and utilities for everyday development. Speed up common tasks, keep code clean, and add reusable tooling to new or existing Laravel apps.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require ermradulsharma/laravel-toolkit
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Ermradulsharma\Toolkit\ToolkitServiceProvider" --tag="config"
    
  2. First Use Case: Artisan Commands The package includes utility commands. Run:

    php artisan toolkit:list
    

    This lists available toolkit commands (e.g., toolkit:make:model, toolkit:make:controller).

  3. Key Features to Explore

    • Model/Controller/Resource Generation: Extends Laravel’s scaffolding with additional options.
    • API Response Helpers: Simplifies JSON responses (e.g., Toolkit::success(), Toolkit::error()).
    • Request Validation: Predefined validation rules or custom rule extensions.
    • Testing Utilities: Mocking helpers or test data factories.

Implementation Patterns

1. Scaffolding with Custom Logic

Pattern: Extend Laravel’s generators with toolkit-specific defaults.

// Example: Custom model with timestamps disabled by default
php artisan toolkit:make:model Post -d --no-timestamps

Workflow:

  • Use toolkit:make:model instead of make:model for pre-configured traits (e.g., HasSoftDeletes).
  • Override stubs in resources/views/vendor/toolkit/stubs/ to inject custom logic (e.g., API resource fields).

2. API Response Standardization

Pattern: Replace manual return response()->json() with toolkit helpers.

use Ermradulsharma\Toolkit\Facades\Toolkit;

public function show(User $user) {
    return Toolkit::success($user, 200, ['meta' => ['api_version' => 'v1']]);
}

Integration Tips:

  • Configure default response formats in config/toolkit.php (e.g., error codes, meta fields).
  • Extend with middleware to wrap all API responses:
    Toolkit::setResponseWrapper(function ($response) {
        return $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
    });
    

3. Validation Layer

Pattern: Reuse validation rules across projects.

use Ermradulsharma\Toolkit\Rules\CustomRule;

$request->validate([
    'email' => ['required', new CustomRule],
]);

Workflow:

  • Define rules in app/Rules/ and register them in ToolkitServiceProvider.
  • Use toolkit:make:rule to generate custom rules with built-in methods (e.g., passes(), message()).

4. Testing Utilities

Pattern: Seed test data or mock responses efficiently.

// Seed factories
php artisan toolkit:factory:make UserFactory --count=10

// Mock API responses
Toolkit::mockHttpResponse('users/show', [
    'id' => 1,
    'name' => 'Test User',
]);

Tip: Combine with Laravel’s testing helpers for seamless integration:

$this->get('/api/users/1')->assertJsonToolkitSuccess();

Gotchas and Tips

Pitfalls

  1. Stub Overrides

    • Custom stubs in resources/views/vendor/toolkit/stubs/ may conflict with package updates. Use php artisan toolkit:stub:publish to merge changes safely.
  2. Configuration Clashes

    • The package auto-loads some defaults (e.g., API response structure). Override via config/toolkit.php:
      'api' => [
          'default_status' => 201, // Override default success status
      ],
      
  3. Command Naming Collisions

    • Avoid naming custom commands toolkit:* to prevent conflicts. Use namespaces:
      php artisan make:command MyToolkitCommand
      

Debugging

  • Log Toolkit Events: Enable debug mode in config:
    'debug' => env('TOOLKIT_DEBUG', false),
    
  • Command Output: Use --verbose flag for detailed logs:
    php artisan toolkit:make:model Post --verbose
    

Extension Points

  1. Custom Commands Extend the toolkit’s command registry in ToolkitServiceProvider:

    public function registerCommands() {
        $this->commands([
            \App\Commands\CustomToolkitCommand::class,
        ]);
    }
    
  2. API Response Macros Add reusable response macros globally:

    Toolkit::macro('customResponse', function ($data) {
        return Toolkit::success($data, 200, ['custom_field' => true]);
    });
    
  3. Validation Rule Sharing Share rules across projects via a package:

    composer require ermradulsharma/laravel-validation-rules
    

    Then use them in any project:

    use Ermradulsharma\ValidationRules\Rules\StrongPassword;
    
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator