Skip to content

Installation

Get Laravel Specifications up and running in your Laravel application in under 5 minutes.

Requirements

  • PHP: 8.1 or higher
  • Laravel: 9.0 or higher
  • Composer: Latest version recommended

Installation

Install the package via Composer:

bash
composer require dangerwayne/laravel-specifications

The package will automatically register its service provider using Laravel's auto-discovery feature.

Publish Configuration (Optional)

Publish the configuration file to customize caching and performance settings:

bash
php artisan vendor:publish --tag=specification-config

This will create config/specification.php:

php
return [
    'cache' => [
        'enabled' => env('SPECIFICATION_CACHE_ENABLED', false),
        'ttl' => env('SPECIFICATION_CACHE_TTL', 3600),
        'prefix' => env('SPECIFICATION_CACHE_PREFIX', 'spec_'),
    ],
    
    'performance' => [
        'lazy_collections' => env('SPECIFICATION_USE_LAZY', true),
        'chunk_size' => env('SPECIFICATION_CHUNK_SIZE', 1000),
    ],
];

Publish Stub Templates (Optional)

Customize the Artisan generator templates:

bash
php artisan vendor:publish --tag=specification-stubs

This publishes stub files to resources/stubs/specification/ where you can modify them to match your coding standards.

Verify Installation

Test that everything is working by generating your first specification:

bash
php artisan make:specification TestSpecification

You should see:

Specification created successfully.

The file will be created at app/Specifications/TestSpecification.php.

Environment Configuration

Add these optional environment variables to your .env file:

env
# Specification caching (recommended for production)
SPECIFICATION_CACHE_ENABLED=false
SPECIFICATION_CACHE_TTL=3600

# Performance tuning
SPECIFICATION_USE_LAZY=true
SPECIFICATION_CHUNK_SIZE=1000

What's Next?

Now that you have Laravel Specifications installed:

  1. Create your first specification →
  2. Learn the Artisan generator →
  3. See transformation examples →

Troubleshooting

Class Not Found

If you get a "Class not found" error, make sure to run:

bash
composer dump-autoload

Service Provider Not Registered

If the Artisan command isn't available, manually register the service provider in config/app.php:

php
'providers' => [
    // Other providers...
    DangerWayne\Specification\Providers\SpecificationServiceProvider::class,
],

Stub Publishing Issues

If stub publishing fails, ensure your resources/ directory is writable:

bash
chmod -R 755 resources/

Released under the MIT License.