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

Easy Dev Laravel Package

anas/easy-dev

Interactive Laravel code generator for complete CRUD with repository/service patterns. Auto-detects model relationships and scaffolds policies, DTOs, observers, filters, enums, API resources, routes, and more, with dry-run mode and customizable stubs.

View on GitHub
Deep Wiki
Context7

Laravel Easy Dev - Advanced Usage Guide

This guide covers advanced features and use cases for Laravel Easy Dev package.

๐Ÿ—๏ธ Architecture Patterns

Repository Pattern

The Repository pattern provides a layer of abstraction between your business logic and data access logic.

Basic Repository Generation

php artisan easy-dev:repository User

Generated files:

  • app/Repositories/UserRepository.php
  • app/Repositories/Contracts/UserRepositoryInterface.php

Repository Structure

<?php

namespace App\Repositories;

use App\Models\User;
use App\Repositories\Contracts\UserRepositoryInterface;
use Illuminate\Database\Eloquent\Collection;

class UserRepository implements UserRepositoryInterface
{
    public function __construct(
        protected User $model
    ) {}

    public function getAll(): Collection
    {
        return $this->model->all();
    }

    public function findById(int $id): ?User
    {
        return $this->model->find($id);
    }

    public function create(array $data): User
    {
        return $this->model->create($data);
    }

    public function update(User $user, array $data): User
    {
        $user->update($data);
        return $user;
    }

    public function delete(User $user): bool
    {
        return $user->delete();
    }
}

Service Layer Pattern

The Service layer contains business logic and coordinates between controllers and repositories.

Service Generation

php artisan easy-dev:crud Product --with-service --with-repository

Service Structure

<?php

namespace App\Services;

use App\Models\Product;
use App\Services\Contracts\ProductServiceInterface;
use App\Repositories\Contracts\ProductRepositoryInterface;

class ProductService implements ProductServiceInterface
{
    public function __construct(
        protected ProductRepositoryInterface $repository
    ) {}

    public function createProduct(array $data): Product
    {
        // Business logic validation
        $this->validateBusinessRules($data);
        
        // Transform data if needed
        $transformedData = $this->transformData($data);
        
        return $this->repository->create($transformedData);
    }

    protected function validateBusinessRules(array $data): void
    {
        // Custom business validation
        if (isset($data['price']) && $data['price'] < 0) {
            throw new \InvalidArgumentException('Price cannot be negative');
        }
    }
}

๐Ÿ”„ Relationship Detection

Automatic Detection

The package automatically detects relationships from:

  1. Foreign key constraints in database
  2. Migration file analysis
  3. Field naming conventions
# Auto-detect all relationships
php artisan easy-dev:sync-relations

# Detect for specific model
php artisan easy-dev:sync-relations User

Supported Relationship Types

belongsTo Relationships

Detected from:

  • user_id field โ†’ belongsTo(User::class)
  • category_id field โ†’ belongsTo(Category::class)
  • Foreign key constraints

hasMany Relationships

Detected by reverse lookup:

  • If posts table has user_id โ†’ User hasMany Post

Polymorphic Relationships

Detected from:

  • commentable_id + commentable_type โ†’ morphTo()
  • Migration morphs() method
// Generated polymorphic relationships
public function commentable()
{
    return $this->morphTo();
}

public function comments()
{
    return $this->morphMany(Comment::class, 'commentable');
}

๐ŸŽจ Customization

Stub Templates

Publish and customize stub templates:

php artisan vendor:publish --tag=easy-dev-stubs

Available stubs:

  • model.enhanced.stub - Enhanced model template
  • controller.api.stub - API controller template
  • controller.web.stub - Web controller template
  • repository.stub - Repository template
  • service.stub - Service template

Configuration

Publish configuration:

php artisan vendor:publish --tag=easy-dev-config

Configuration options:

<?php

return [
    // File generation paths
    'paths' => [
        'models' => app_path('Models'),
        'controllers' => app_path('Http/Controllers'),
        'repositories' => app_path('Repositories'),
        'services' => app_path('Services'),
    ],
    
    // Default options
    'defaults' => [
        'with_repository' => false,
        'with_service' => false,
        'generate_tests' => false,
    ],
    
    // Template customization
    'stubs' => [
        'model' => 'model.enhanced',
        'controller' => 'controller.api',
    ],
];

๐Ÿงช Testing Integration

Test Generation

Generate tests along with CRUD:

php artisan easy-dev:crud Product --with-tests

Generated test files:

  • tests/Feature/ProductControllerTest.php
  • tests/Unit/ProductRepositoryTest.php
  • tests/Unit/ProductServiceTest.php

Test Structure

<?php

namespace Tests\Feature;

use App\Models\Product;
use Tests\TestCase;

class ProductControllerTest extends TestCase
{
    /** [@test](https://github.com/test) */
    public function it_can_list_products()
    {
        Product::factory()->count(3)->create();

        $response = $this->getJson('/api/products');

        $response->assertOk()
                ->assertJsonCount(3, 'data');
    }

    /** [@test](https://github.com/test) */
    public function it_can_create_a_product()
    {
        $data = [
            'name' => 'Test Product',
            'price' => 99.99,
        ];

        $response = $this->postJson('/api/products', $data);

        $response->assertCreated()
                ->assertJsonFragment($data);
    }
}

๐ŸŒ API Development

API-Only Generation

php artisan easy-dev:crud Product --api-only

Features:

  • JSON responses
  • API routes only
  • Resource collections
  • Proper HTTP status codes

API Response Structure

// Success responses
{
    "data": {
        "id": 1,
        "name": "Product Name",
        "created_at": "2024-01-01T00:00:00.000000Z"
    }
}

// Error responses
{
    "message": "Validation failed",
    "errors": {
        "name": ["The name field is required."]
    }
}

๐Ÿ”ง Advanced Features

Interactive Mode

Use interactive mode for guided setup:

php artisan easy-dev:make --interactive

Features:

  • Step-by-step wizard
  • Architecture pattern selection
  • Feature selection
  • Visual progress tracking

Batch Operations

Generate multiple CRUDs:

# Using a loop
for model in Product Order Customer; do
    php artisan easy-dev:crud $model --with-repository --with-service
done

Custom Validation Rules

The package generates intelligent validation rules:

// Generated validation in StoreProductRequest
public function rules(): array
{
    return [
        'name' => 'required|string|max:255',
        'email' => 'required|email|max:255',
        'price' => 'required|numeric|min:0',
        'is_active' => 'required|boolean',
        'category_id' => 'required|integer|exists:categories,id',
    ];
}

๐Ÿ› Troubleshooting

Common Issues

Migration Not Found

Problem: Package can't find migration file Solution: Ensure migration follows Laravel naming convention

# Correct naming
create_products_table

# Incorrect naming
products_migration

Model Not Enhanced

Problem: Existing model not updated with relationships Solution: Use sync-relations command

php artisan easy-dev:sync-relations Product

Route Conflicts

Problem: Routes not generated or conflicting Solution: Check existing routes and use specific options

# Generate only API routes
php artisan easy-dev:crud Product --api-only

Debug Mode

Enable debug output:

php artisan easy-dev:crud Product --verbose

๐Ÿ“Š Performance Tips

Large Applications

For large applications with many models:

  1. Use specific model sync:

    php artisan easy-dev:sync-relations User
    
  2. Generate in batches:

    # Core models first
    php artisan easy-dev:crud User --with-repository --with-service
    
    # Related models
    php artisan easy-dev:crud Post --with-repository
    
  3. Use without-interface for simpler structure:

    php artisan easy-dev:crud Product --with-repository --without-interface
    

๐Ÿš€ Best Practices

1. Architecture Decisions

Use Repository Pattern When:

  • Large applications
  • Complex data access logic
  • Multiple data sources
  • Testing is priority

Use Service Layer When:

  • Complex business logic
  • Multiple repositories needed
  • External API integrations
  • Domain-driven design

2. Command Usage

Interactive Mode For:

  • New team members
  • Complex configurations
  • Learning the package

Direct Commands For:

  • CI/CD pipelines
  • Scripted generation
  • Known configurations

3. Customization

Publish Stubs When:

  • Consistent code style needed
  • Company-specific templates
  • Additional features required

This guide covers the advanced features of Laravel Easy Dev. For basic usage, see the main README.

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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours