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

Reference Clothing Laravel Package

baks-dev/reference-clothing

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require baks-dev/reference-clothing
    

    Ensure your composer.json requires PHP 8.4+.

  2. First Use Case: Fetch all available sizes in a Laravel controller or service:

    use BaksDev\ReferenceClothing\Facades\ClothingSize;
    
    $sizes = ClothingSize::all(); // Returns array of size labels (e.g., ['2XS', 'XS', ..., '7XL'])
    
  3. Where to Look First:

    • Facade: BaksDev\ReferenceClothing\Facades\ClothingSize (primary entry point).
    • Service Provider: Check config/clothing-sizes.php for customizable defaults.
    • Tests: Review tests/Feature/ClothingSizeTest.php for edge cases (e.g., invalid inputs).

Implementation Patterns

Core Workflows

  1. Fetching Sizes:

    • All sizes:
      $allSizes = ClothingSize::all(); // ['2XS', 'XS', ..., '7XL']
      
    • Filtered by range:
      $adultSizes = ClothingSize::filter(fn($size) => str_starts_with($size, ['S', 'M', 'L', 'XL']));
      
  2. Integration with Eloquent: Add a size column to a Product model and validate against the package:

    use BaksDev\ReferenceClothing\Rules\ValidClothingSize;
    
    class Product extends Model {
        protected $casts = ['size' => 'string'];
    
        protected function rules() {
            return [
                'size' => ['required', new ValidClothingSize],
            ];
        }
    }
    
  3. Localization: Override default labels via config:

    // config/clothing-sizes.php
    'labels' => [
        '2XS' => 'Двойной экстра-малыш',
        'XS'  => 'Экстра-малыш',
        // ...
    ],
    

    Then fetch localized sizes:

    $localizedSizes = ClothingSize::getLocalizedLabels();
    
  4. API Responses: Use the package to standardize size responses:

    return response()->json([
        'product' => [
            'name' => 'T-Shirt',
            'sizes' => ClothingSize::all(), // Consistent format
        ],
    ]);
    
  5. Frontend Integration: Pass sizes to Blade:

    @php
        $sizes = \BaksDev\ReferenceClothing\Facades\ClothingSize::all();
    @endphp
    <select>
        @foreach($sizes as $size)
            <option>{{ $size }}</option>
        @endforeach
    </select>
    

Gotchas and Tips

Pitfalls

  1. Case Sensitivity: The package treats sizes as case-sensitive (e.g., '2xs''2XS'). Normalize inputs:

    $normalizedSize = strtoupper($userInput);
    
  2. Missing Config: If extending labels, ensure the config file exists (config/clothing-sizes.php). Run:

    php artisan vendor:publish --provider="BaksDev\ReferenceClothing\ClothingSizeServiceProvider"
    
  3. Validation Rule Scope: The ValidClothingSize rule defaults to all sizes. Restrict it to a subset (e.g., adult sizes) by passing a closure:

    new ValidClothingSize(fn($size) => str_contains($size, ['S', 'M', 'L', 'XL']))
    
  4. Performance: Avoid calling ClothingSize::all() in loops. Cache the result:

    $sizes = Cache::remember('clothing.sizes', now()->addHours(1), fn() => ClothingSize::all());
    

Debugging

  • Invalid Size Errors: Use the ClothingSize::isValid($size) method to debug:
    if (!ClothingSize::isValid('8XL')) {
        // Handle error
    }
    
  • Facade Not Found: Ensure the service provider is registered in config/app.php under providers.

Extension Points

  1. Custom Size Ranges: Extend the base class to add niche sizes (e.g., shoe sizes):

    use BaksDev\ReferenceClothing\Contracts\SizeCollection;
    
    class ShoeSizeCollection implements SizeCollection {
        public function all(): array {
            return ['35', '36', ..., '45'];
        }
    }
    

    Register it via the service provider’s extend() method.

  2. Dynamic Label Generation: Override the getLocalizedLabels() method in a custom facade:

    class CustomClothingSizeFacade extends Facade {
        public static function getLocalizedLabels(): array {
            return array_map(fn($size) => "Размер: {$size}", parent::getLocalizedLabels());
        }
    }
    
  3. Database Seeding: Seed a sizes table using the package’s data:

    use BaksDev\ReferenceClothing\Facades\ClothingSize;
    
    DB::table('sizes')->insert(
        array_map(fn($size) => ['name' => $size], ClothingSize::all())
    );
    
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.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php