Skip to content

Installation Setup

Jean-Marc Strauven edited this page Aug 6, 2025 · 1 revision

πŸ“¦ Installation & Setup

Get Laravel Arc up and running in your Laravel application in just a few minutes.

Requirements

  • PHP: 8.3 or higher
  • Laravel: 10.x or 11.x
  • Composer: Latest version recommended

Installation

1. Install via Composer

composer require grazulex/laravel-arc

2. Publish Configuration (Optional)

php artisan vendor:publish --provider="Grazulex\LaravelArc\LaravelArcServiceProvider" --tag="config"

This creates config/arc.php with default settings.

3. Create DTO Directory Structure

Laravel Arc follows Laravel conventions. Create your YAML definitions in:

resources/
└── arc/
    β”œβ”€β”€ user.yaml
    β”œβ”€β”€ product.yaml
    └── nested/
        └── address.yaml

Basic Configuration

The default configuration works out of the box, but you can customize it in config/arc.php:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Default DTO Namespace
    |--------------------------------------------------------------------------
    | The default namespace for generated DTOs when not specified in YAML
    */
    'default_namespace' => 'App\\DTOs',

    /*
    |--------------------------------------------------------------------------
    | Default Output Directory
    |--------------------------------------------------------------------------
    | Where generated DTO files will be saved
    */
    'output_path' => app_path('DTOs'),

    /*
    |--------------------------------------------------------------------------
    | YAML Definitions Path
    |--------------------------------------------------------------------------
    | Default location for YAML definition files
    */
    'definitions_path' => resource_path('arc'),

    /*
    |--------------------------------------------------------------------------
    | Field Transformers
    |--------------------------------------------------------------------------
    | Enable automatic field transformation
    */
    'enable_transformers' => true,

    /*
    |--------------------------------------------------------------------------
    | Validation Integration
    |--------------------------------------------------------------------------
    | Auto-generate Laravel validation rules
    */
    'auto_validation' => true,
];

Verification

Verify your installation by running:

php artisan arc:list

You should see available Arc commands:

Available commands:
  arc:generate    Generate DTO from YAML definition
  arc:list        List all available YAML definitions
  arc:validate    Validate YAML definition syntax

Directory Structure After Setup

After installation, your project structure should look like:

your-laravel-app/
β”œβ”€β”€ app/
β”‚   └── DTOs/                 # Generated DTO classes (auto-created)
β”œβ”€β”€ config/
β”‚   └── arc.php              # Configuration file (optional)
β”œβ”€β”€ resources/
β”‚   └── arc/                 # YAML definitions directory
└── vendor/
    └── grazulex/laravel-arc/ # Package files

Quick Test

Create a simple test to verify everything works:

1. Create Test YAML

mkdir -p resources/arc

Create resources/arc/test.yaml:

header:
  class: TestDto
  namespace: App\DTOs

fields:
  message:
    type: string
    required: true

2. Generate DTO

php artisan arc:generate resources/arc/test.yaml

3. Use in Code

use App\DTOs\TestDto;

$dto = TestDto::from(['message' => 'Hello Laravel Arc!']);
echo $dto->message; // "Hello Laravel Arc!"

Common Issues & Solutions

Permission Issues

If you encounter permission errors:

sudo chown -R $USER:$USER app/DTOs
chmod -R 755 app/DTOs

Namespace Issues

Ensure your composer.json has the correct PSR-4 autoloading:

{
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "App\\DTOs\\": "app/DTOs/"
        }
    }
}

Run composer dump-autoload after changes.

Class Not Found

If generated classes aren't found:

  1. Check the namespace in your YAML matches your autoloader
  2. Run composer dump-autoload
  3. Clear Laravel cache: php artisan cache:clear

What's Next?

βœ… Installation Complete!

Now you're ready to:


Need help? Check the troubleshooting guide above or refer to our examples.

πŸš€ Laravel Arc Wiki

🏠 Home

πŸš€ Getting Started

πŸ“š Core Concepts

πŸ—οΈ Advanced Features

βš™οΈ Configuration & CLI

🌐 Real-World Examples


🎯 Key Concepts

YAML β†’ DTO β†’ Type-Safe Code

Laravel Arc transforms your YAML definitions into powerful PHP DTOs with automatic validation, field transformers, and behavioral traits.

πŸ”— Quick Links

Clone this wiki locally