### E-commerce System Relationship Scaffolding (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Example commands for scaffolding an e-commerce system using Laravel TurboMaker, illustrating the setup of relationships between User, Product, Order, OrderItem, and Invoice models. ```bash # User can have many orders php artisan turbo:make User --has-many=Order # Product belongs to category, has many order items php artisan turbo:make Product --belongs-to=Category --has-many=OrderItem # Order belongs to user, has many items, has one invoice php artisan turbo:make Order --belongs-to=User --has-many=OrderItem --has-one=Invoice # OrderItem belongs to order and product php artisan turbo:make OrderItem --belongs-to=Order --belongs-to=Product # Invoice belongs to order php artisan turbo:make Invoice --belongs-to=Order ``` -------------------------------- ### Generate E-commerce System Components (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Provides example commands for generating various components of an e-commerce system using Laravel TurboMaker. This covers models like `Category`, `Brand`, `Product`, `Order`, `OrderItem`, and `Payment`, with options for defining relationships, tests, factories, policies, observers, services, and actions. ```bash # Product Management php artisan turbo:make Category --has-many=Product --tests --factory php artisan turbo:make Brand --has-many=Product --tests --factory php artisan turbo:make Product --belongs-to=Category --belongs-to=Brand --has-many=OrderItem --policies --tests --factory --observers # Order Management php artisan turbo:make Order --belongs-to=User --has-many=OrderItem --has-one=Payment --services --actions --observers --tests php artisan turbo:make OrderItem --belongs-to=Order --belongs-to=Product --tests --factory php artisan turbo:make Payment --belongs-to=Order --tests --factory --observers ``` -------------------------------- ### Clone and Install Laravel TurboMaker Source: https://github.com/grazulex/laravel-turbomaker/blob/main/README.md This snippet shows how to clone the Laravel TurboMaker repository, install its dependencies using Composer, and run the Pest test suite for development setup. ```bash git clone https://github.com/grazulex/laravel-turbomaker.git cd laravel-turbomaker composer install ./vendor/bin/pest ``` -------------------------------- ### Configure TurboMaker Defaults for Team Development (PHP) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Shows a configuration example for `config/turbomaker.php` demonstrating how to set default generation options for team development, such as enabling tests, factories, and policies. It also includes model-specific configurations like using UUIDs and default traits. ```php // config/turbomaker.php return [ 'defaults' => [ 'generate_tests' => true, 'generate_factory' => true, 'generate_policies' => true, ], 'model' => [ 'use_uuids' => true, 'default_traits' => [ 'Illuminate\Database\Eloquent\SoftDeletes', 'App\Traits\Auditable', ], ], ]; ``` -------------------------------- ### Set Environment Variables for TurboMaker (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Illustrates how to configure TurboMaker settings using environment variables, specifically for local development. This example shows how to enable test and factory generation via `.env.local`. ```bash # .env.local TURBOMAKER_GENERATE_TESTS=true TURBOMAKER_GENERATE_FACTORY=true ``` -------------------------------- ### Blog System Relationship Scaffolding (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Example commands for scaffolding a blog system using Laravel TurboMaker, demonstrating how to set up relationships between User, Post, and Comment models. ```bash # Create User model first (if not exists) php artisan turbo:make User --has-many=Post # Create Category php artisan turbo:make Category --has-many=Post # Create Post with relationships php artisan turbo:make Post --belongs-to=User --belongs-to=Category --has-many=Comment # Create Comment php artisan turbo:make Comment --belongs-to=Post --belongs-to=User ``` -------------------------------- ### Schema Processing Example Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture An example of a user schema definition in YAML format, showcasing V2.1.0 features like custom types and precision for fields. ```yaml # User schema with V2.1.0 features core: model: User table: users fields: name: type: string nullable: false email: type: email unique: true balance: type: money currency: EUR precision: 2 relations: posts: type: hasMany model: App\Models\Post ``` -------------------------------- ### OrderObserver Example Source: https://github.com/grazulex/laravel-turbomaker/wiki/Advanced-Usage An example of an OrderObserver class demonstrating how to handle 'created' and 'updated' events for an Order model. It includes dispatching events, sending notifications, and updating inventory, showcasing common observer patterns. ```php class OrderObserver { public function created(Order $order) { // Dispatch events OrderCreated::dispatch($order); // Send notifications $order->user->notify(new OrderConfirmation($order)); // Update inventory UpdateInventoryJob::dispatch($order); } public function updated(Order $order) { if ($order->wasChanged('status')) { OrderStatusChanged::dispatch($order, $order->getOriginal('status')); } } } ``` -------------------------------- ### Model Fragment Structure Example Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture Provides a detailed JSON example of a model fragment, outlining its structure including class name, table, namespace, fields, relations, traits, and options. ```json { "model": { "class_name": "User", "table": "users", "namespace": "App\\Models", "fields": [ { "name": "name", "type": "string", "nullable": false, "cast": "string" }, { "name": "balance", "type": "decimal", "precision": 10, "scale": 2, "cast": "decimal:2" } ], "relations": [ { "type": "hasMany", "name": "posts", "model": "App\\Models\\Post" } ], "traits": ["HasFactory", "SoftDeletes"], "options": { "timestamps": true, "soft_deletes": true } } } ``` -------------------------------- ### Generate Module with TDD Focus (Artisan) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This command generates a module with a focus on Test-Driven Development (TDD). It includes tests, factory, API resources, and policies, ensuring comprehensive testing from the start. ```bash php artisan turbo:make Product --tests --factory --api --policies ``` -------------------------------- ### Demonstrate TurboMaker Performance Improvement (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Compares the execution time of the traditional V2.0 `turbo:make` command with the V2.1.0 Fragment Architecture `turbo:fragments` command. This highlights the significant performance improvement in V2.1.0. ```bash # Traditional approach (V2.0) time php artisan turbo:make Product # real 0m2.341s # Fragment Architecture (V2.1.0) time php artisan turbo:fragments Product --analyze # real 0m0.087s (96% faster!) ``` -------------------------------- ### Schema Compatibility Example (YAML) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture Illustrates the schema structure for V2.0 and the enhanced V2.1.0 versions. V2.1.0 introduces a more detailed structure with explicit type definitions and validation rules. ```yaml # V2.0 Schema (still supported) model: User fields: name: string email: string # V2.1.0 Enhanced Schema core: model: User table: users fields: name: type: string nullable: false email: type: email unique: true ``` -------------------------------- ### Generate E-commerce System Models and Relationships Source: https://context7.com/grazulex/laravel-turbomaker/llms.txt This bash command example illustrates the generation of models for an e-commerce system, focusing on product management. It demonstrates creating `Category`, `Brand`, and `Product` models, defining their relationships (`has-many`, `belongs-to`), and enabling features like policies, tests, factories, and observers. ```bash # Product Management php artisan turbo:make Category --has-many=Product --tests --factory php artisan turbo:make Brand --has-many=Product --tests --factory php artisan turbo:make Product \ --belongs-to=Category \ --belongs-to=Brand \ --has-many=OrderItem \ --policies \ --tests \ --factory \ --observers ``` -------------------------------- ### CRM System Relationship Scaffolding (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Example commands for scaffolding a CRM system using Laravel TurboMaker, showing how to define relationships between Company, Contact, Project, and Task models. ```bash # Company has many contacts and projects php artisan turbo:make Company --has-many=Contact --has-many=Project # Contact belongs to company, has many projects (many-to-many would need manual setup) php artisan turbo:make Contact --belongs-to=Company # Project belongs to company and has many tasks php artisan turbo:make Project --belongs-to=Company --has-many=Task # Task belongs to project and optionally to contact (assignee) php artisan turbo:make Task --belongs-to=Project --belongs-to=Contact ``` -------------------------------- ### Laravel Turbomaker E-commerce Product Commands (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Provides Artisan commands for managing the e-commerce product schema. Includes commands to create the schema file, generate code (models, views, tests, etc.) from the schema, and validate the schema's integrity. ```bash # Create schema php artisan turbo:schema create Product --template=ecommerce # Generate from schema php artisan turbo:from-schema Product --views --tests --factory --seeder --policies # Validate schema php artisan turbo:schema validate Product ``` -------------------------------- ### List and Show Schema Commands (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Schema-System Provides examples for the `php artisan turbo:schema list` command to view all available schemas and `php artisan turbo:schema show` to display details of a specific schema. ```bash # List all available schemas php artisan turbo:schema list # Show schema details php artisan turbo:schema show product ``` -------------------------------- ### Install Core Laravel TurboMaker Package Source: https://github.com/grazulex/laravel-turbomaker/wiki/Getting-Started Installs the main Laravel TurboMaker package using Composer. This is a development dependency. ```bash composer require --dev grazulex/laravel-turbomaker ``` -------------------------------- ### Custom Model Stub Template (PHP) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples An example of a custom model stub file for Turbomaker, demonstrating how to extend base classes and include traits like SoftDeletes and Auditable. It defines fillable fields, casts, and placeholders for relationships. ```php 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; {{ relationships }} } ``` -------------------------------- ### Schema-First Development Workflow with Laravel TurboMaker Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This bash script outlines the steps for schema-first development using Laravel TurboMaker. It covers creating a schema from a template, customizing the schema file, validating the schema, generating a complete module from the schema (including views, tests, factory, seeder, and policies), and finally running database migrations. ```bash # 1. Create schema with template php artisan turbo:schema create Product --template=ecommerce # 2. Customize schema in resources/schemas/product.schema.yml # 3. Validate schema php artisan turbo:schema validate Product # 4. Generate complete module from schema php artisan turbo:from-schema Product --views --tests --factory --seeder --policies # 5. Run migrations php artisan migrate --seed ``` -------------------------------- ### Generate API-Only Application Components (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Illustrates commands for generating components for an API-only application using Laravel TurboMaker. This includes options for adding tests, factories, policies, and defining relationships for different models like `Product`, `Category`, and `Order`. ```bash php artisan turbo:api Product --tests --factory --policiesphp artisan turbo:api Category --tests --factory php artisan turbo:api Order --belongs-to=User --has-many=OrderItem --tests --policies ``` -------------------------------- ### Blog System Relationships Example (YAML) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Schema-System Illustrates defining multiple relationships for a 'Post' model in a blog system, including belongsTo for author and category, belongsToMany for tags, hasMany for comments, and morphOne for a featured image. ```yaml # Post model relationships: author: type: belongsTo model: "User" foreign_key: "author_id" category: type: belongsTo model: "Category" tags: type: belongsToMany model: "Tag" pivot_table: "post_tags" comments: type: hasMany model: "Comment" featured_image: type: morphOne model: "Image" morph_name: "imageable" ``` -------------------------------- ### Generate Models with Complex Relationships (Artisan) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This command sequence demonstrates how to generate models with multi-level relationships using Turbomaker's Artisan commands. It sets up relationships like 'has-many' and 'belongs-to' for an e-commerce-like structure. ```bash # Order -> OrderItem -> Product -> Category php artisan turbo:make Category --has-many=Product php artisan turbo:make Product --belongs-to=Category --has-many=OrderItem php artisan turbo:make Order --has-many=OrderItem php artisan turbo:make OrderItem --belongs-to=Order --belongs-to=Product ``` -------------------------------- ### Generate Payment Model with Relationships, Factory, and Observers Source: https://context7.com/grazulex/laravel-turbomaker/llms.txt This command generates the 'Payment' model, linking it to the 'Order' model. It includes setup for tests, a factory, and observers for event handling. ```bash php artisan turbo:make Payment \ --belongs-to=Order \ --tests \ --factory \ --observers ``` -------------------------------- ### Generate Enterprise Fragments for Product Model (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Demonstrates the command to generate enterprise-level fragments for a `Product` model using TurboMaker V2.1.0. It includes options for processing enterprise field types and analyzing the generation process, showcasing significant speed improvements. ```bash php artisan turbo:fragments Product --enterprise --analyze # Output: ✅ Schema parsed: 8ms ✅ Enterprise field types processed: 15ms ✅ 13 component fragments generated: 32ms ✅ Security validation passed: 6ms 📊 Total: 61ms (97% faster than traditional) ``` -------------------------------- ### Generate Module with Service Layer (Artisan) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This Artisan command generates a complete module including service layer components, actions, observers, and tests. This is useful for building complex applications with a structured architecture. ```bash php artisan turbo:make Order --services --actions --observers --tests ``` -------------------------------- ### E-commerce System Relationships Example (YAML) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Schema-System Demonstrates defining relationships for an 'Order' model in an e-commerce system, including belongsTo for customer and addresses, and belongsToMany for products with pivot columns for quantity and price. ```yaml # Order model relationships: customer: type: belongsTo model: "User" foreign_key: "customer_id" products: type: belongsToMany model: "Product" pivot_table: "order_items" pivot_columns: ["quantity", "price", "created_at"] shipping_address: type: belongsTo model: "Address" foreign_key: "shipping_address_id" billing_address: type: belongsTo model: "Address" foreign_key: "billing_address_id" ``` -------------------------------- ### Generating Models with Relationships and Tests (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Shows the command-line usage for generating a Post model with BelongsTo and HasMany relationships, including factory and test generation. This command simplifies the setup of models with interconnected data. ```bash php artisan turbo:make Post --belongs-to=User --has-many=Comment --tests --factory ``` -------------------------------- ### E-commerce Product Schema Definition (YAML) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples Defines a comprehensive schema for an e-commerce product, including fields for name, price, stock, images, and relationships to categories, brands, and tags. This YAML file serves as the blueprint for generating database tables and related code. ```yaml name: "Product" table_name: "products" fields: name: type: string length: 255 nullable: false validation: ["min:3", "max:255"] index: true slug: type: string length: 255 unique: true validation: ["regex:/^[a-z0-9-]+$/"] description: type: longText nullable: true price: type: decimal attributes: { precision: 10, scale: 2 } validation: ["numeric", "min:0"] compare_price: type: decimal attributes: { precision: 10, scale: 2 } nullable: true validation: ["numeric", "min:0"] cost_price: type: decimal attributes: { precision: 10, scale: 2 } nullable: true validation: ["numeric", "min:0"] sku: type: string length: 100 unique: true nullable: true barcode: type: string length: 100 nullable: true stock_quantity: type: integer default: 0 validation: ["min:0"] weight: type: decimal attributes: { precision: 8, scale: 2 } nullable: true validation: ["numeric", "min:0"] dimensions: type: json nullable: true comment: "Length, width, height in cm" is_active: type: boolean default: true is_featured: type: boolean default: false meta_title: type: string length: 60 nullable: true meta_description: type: string length: 160 nullable: true published_at: type: datetime nullable: true relationships: category: type: belongsTo model: "Category" foreign_key: "category_id" brand: type: belongsTo model: "Brand" foreign_key: "brand_id" tags: type: belongsToMany model: "Tag" pivot_table: "product_tags" images: type: morphMany model: "Image" morph_name: "imageable" reviews: type: hasMany model: "Review" variants: type: hasMany model: "ProductVariant" ``` -------------------------------- ### Progressive Module Enhancement (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Commands Illustrates a progressive enhancement strategy for module development. It starts with a basic module generation using `turbo:make`, adds API capabilities with `turbo:api`, and suggests using `turbo:schema` for more intricate projects. ```bash php artisan turbo:make Post php artisan turbo:api Post php artisan turbo:schema create Post --template=blog ``` -------------------------------- ### Generate Optimized Database Structures (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Advanced-Usage This command generates a new 'Product' model with factory and seeder. It also includes a comment suggesting manual addition of database indexes for performance enhancement after generation. The provided migration example demonstrates how to add these indexes. ```bash # Generate with database optimizations php artisan turbo:make Product --factory --seeder # Add database indexes manually after generation ``` -------------------------------- ### Organize Fields Logically in YAML Source: https://github.com/grazulex/laravel-turbomaker/wiki/Schema-System This YAML example illustrates a recommended approach to organizing fields within a database schema. Fields are grouped by their purpose, such as core identification, content, status, metadata, and relationships, improving schema readability and maintainability. ```yaml fields: # Core identification title: type: string slug: type: string # Content content: type: longText excerpt: type: text # Status and metadata status: type: string published_at: type: datetime # Relationships (foreign keys) author_id: type: unsignedBigInteger ``` -------------------------------- ### Generated Model with Relationships (PHP) Source: https://context7.com/grazulex/laravel-turbomaker/llms.txt This code snippet shows an example of a generated Eloquent model (`Post`) that includes the necessary methods and type hints for the defined relationships (BelongsTo for `user` and `category`, HasMany for `comments`). It also includes the `$fillable` property for mass assignment. ```php belongsTo(User::class); } public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function comments(): HasMany { return $this->hasMany(Comment::class); } } ``` -------------------------------- ### Set Up Schema Directory Source: https://github.com/grazulex/laravel-turbomaker/wiki/Commands Ensure your project has a dedicated directory for schemas by creating `resources/schemas` and setting appropriate file permissions for secure access. ```bash # Create schemas directory mkdir -p resources/schemas # Set permissions chmod 755 resources/schemas ``` -------------------------------- ### Install ModelSchema Dependency Source: https://github.com/grazulex/laravel-turbomaker/wiki/Getting-Started Installs the Laravel ModelSchema package, a core dependency for Laravel TurboMaker V2.1.0. This package is essential for the Fragment Architecture. ```bash composer require grazulex/laravel-modelschema ``` -------------------------------- ### E-commerce Product Schema Example with Laravel Turbomaker Source: https://github.com/grazulex/laravel-turbomaker/wiki/Field-Types Provides a complete YAML schema example for an e-commerce product, utilizing various data types and options supported by Laravel Turbomaker. ```yaml fields: name: type: string length: 255 nullable: false validation: ["min:3"] slug: type: string length: 255 unique: true validation: ["regex:/^[a-z0-9-]+$/"] price: type: decimal attributes: { precision: 10, scale: 2 } validation: ["numeric", "min:0"] description: type: longText nullable: true is_active: type: boolean default: true stock_quantity: type: integer default: 0 validation: ["min:0"] metadata: type: json nullable: true published_at: type: datetime nullable: true ``` -------------------------------- ### User Profile Schema Example with Laravel Turbomaker Source: https://github.com/grazulex/laravel-turbomaker/wiki/Field-Types Presents a comprehensive YAML schema example for a user profile, demonstrating the application of different data types and configurations available in Laravel Turbomaker. ```yaml fields: first_name: type: string length: 100 nullable: false last_name: type: string length: 100 nullable: false email: type: email unique: true phone: type: string length: 20 nullable: true birth_date: type: date nullable: true validation: ["before:today"] avatar_url: type: url nullable: true bio: type: text nullable: true is_verified: type: boolean default: false ``` -------------------------------- ### Generate Blog System Models and Relationships Source: https://context7.com/grazulex/laravel-turbomaker/llms.txt This set of bash commands demonstrates how to generate models for a blog system using the `turbo:make` Artisan command. It shows how to define relationships such as `has-many` and `belongs-to`, and enable features like policies, tests, factories, and seeders during model generation. ```bash # Generate User model (if not exists) php artisan turbo:make User --has-many=Post --has-many=Comment --policies --tests --factory # Generate Category php artisan turbo:make Category --has-many=Post --tests --factory # Generate Post with relationships php artisan turbo:make Post \ --belongs-to=User \ --belongs-to=Category \ --has-many=Comment \ --policies \ --tests \ --factory \ --seeder \ --observers # Generate Comment php artisan turbo:make Comment \ --belongs-to=Post \ --belongs-to=User \ --policies \ --tests \ --factory # Run migrations php artisan migrate --seed # Relationship structure: # User (1) -----> (M) Post (M) <----- (1) Category # | | # v v # (M) Comment <------- (M) Comment ``` -------------------------------- ### List, Show, and Validate Schemas Source: https://github.com/grazulex/laravel-turbomaker/wiki/Commands Manage existing schemas using the `list`, `show`, and `validate` actions. `list` displays all available schemas, `show` provides detailed information about a specific schema, and `validate` checks the schema's structure against ModelSchema rules. ```bash # List all available schemas php artisan turbo:schema list # Show detailed schema information php artisan turbo:schema show Product # Validate schema structure php artisan turbo:schema validate Product ``` -------------------------------- ### Complete V2.1.0 Schema Example (YAML) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Schema-System An extensive example of a V2.1.0 schema definition for an e-commerce product. It showcases various field types (uuid, string, money, enum, point, json, set, encrypted), advanced relationships (belongsTo, hasMany, belongsToMany), and model options (timestamps, soft_deletes). It also includes TurboMaker-specific extensions for views, routes, components, API resources, and policies. ```yaml # E-commerce Product Schema - V2.1.0 Enterprise core: model: Product table: products fields: id: type: uuid primary: true nullable: false name: type: string length: 255 nullable: false rules: ['required', 'min:3', 'max:255'] index: true slug: type: string length: 255 unique: true rules: ['required', 'regex:/^[a-z0-9-]+$/'] description: type: text nullable: true rules: ['max:5000'] price: type: money currency: EUR precision: 2 rules: ['required', 'numeric', 'min:0.01'] category: type: enum values: ['electronics', 'clothing', 'books', 'home'] default: 'electronics' index: true location: type: point spatial_index: true nullable: true metadata: type: json nullable: true cast: 'array' tags: type: set values: ['featured', 'sale', 'new', 'trending'] nullable: true encrypted_data: type: encrypted nullable: true relations: category: type: belongsTo model: App\Models\Category foreign_key: category_id reviews: type: hasMany model: App\Models\Review orders: type: belongsToMany model: App\Models\Order pivot_table: order_product with_timestamps: true options: timestamps: true soft_deletes: true # TurboMaker V2.1.0 extensions turbomaker: views: ['index', 'create', 'edit', 'show'] routes: ['api', 'web'] components: ['observers', 'services', 'actions', 'rules'] api_resources: true policies: true ``` -------------------------------- ### Run Database Migrations and Seeders Source: https://context7.com/grazulex/laravel-turbomaker/llms.txt This command executes all pending database migrations and runs the database seeders to populate the database with initial data. ```bash php artisan migrate --seed ``` -------------------------------- ### Configure Turbomaker Generation (Production) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This snippet shows how to configure Turbomaker's code generation behavior for a production environment by disabling test and factory generation. ```env TURBOMAKER_GENERATE_TESTS=false TURBOMAKER_GENERATE_FACTORY=false ``` -------------------------------- ### Conditional Configuration for Traits in PHP Source: https://github.com/grazulex/laravel-turbomaker/wiki/Configuration Conditionally apply default traits to models based on the application environment. For example, exclude certain traits when running in a testing environment. ```php return [ 'model' => [ 'default_traits' => app()->environment('testing') ? [] : [ 'App\Traits\Auditable', 'App\Traits\Cacheable', ], ], ]; ``` -------------------------------- ### Automatic Model Casting with Laravel Turbomaker Source: https://github.com/grazulex/laravel-turbomaker/wiki/Field-Types Demonstrates automatic model casting based on field types in Laravel. Shows examples for boolean, decimal, datetime, and array types. ```php protected $casts = [ 'is_active' => 'boolean', 'price' => 'decimal:2', 'published_at' => 'datetime', 'metadata' => 'array', ]; ``` -------------------------------- ### Define Phone Field Schema in YAML Source: https://github.com/grazulex/laravel-turbomaker/wiki/Custom-Field-Types Example of defining a 'phone' field in the schema configuration. It demonstrates how to specify the country code for phone number formatting and validation. ```yaml fields: phone: type: phone nullable: true attributes: country: "fr" us_phone: type: phone attributes: country: "us" ``` -------------------------------- ### Define Money Field Schema in YAML Source: https://github.com/grazulex/laravel-turbomaker/wiki/Custom-Field-Types Example of defining a 'money' field in the schema configuration. It showcases setting precision, scale, min/max amounts, and validation rules. ```yaml fields: price: type: money attributes: precision: 10 scale: 2 min_amount: 0 max_amount: 999999 validation: ["required"] discount_amount: type: money nullable: true attributes: scale: 3 ``` -------------------------------- ### Customized Model Stub with UUIDs and Soft Deletes Source: https://github.com/grazulex/laravel-turbomaker/wiki/Custom-Templates An example of a customized model stub that incorporates UUIDs and soft delete functionality. It adds necessary traits and casts for these features. ```php 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; {{ relationships }} } ``` -------------------------------- ### Batch Module Generation Script for Laravel TurboMaker Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This bash script automates the generation of a blog system using Laravel TurboMaker. It sequentially generates User, Category, Post, and Comment modules, defining their relationships (has-many, belongs-to) and including options for policies, tests, factories, and seeders. The script concludes by prompting the user to run migrations and seed the database. ```bash #!/bin/bash # generate-blog.sh echo "Generating Blog System..." php artisan turbo:make User --has-many=Post --has-many=Comment --policies --tests --factory php artisan turbo:make Category --has-many=Post --tests --factory php artisan turbo:make Post --belongs-to=User --belongs-to=Category --has-many=Comment --policies --tests --factory --seeder php artisan turbo:make Comment --belongs-to=Post --belongs-to=User --policies --tests --factory echo "Blog system generated successfully!" echo "Run 'php artisan migrate --seed' to set up the database." ``` -------------------------------- ### Generated Model Relationships (PHP) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Example of how Laravel TurboMaker automatically adds relationship methods to your Eloquent models. This snippet shows a 'Post' model with 'belongsTo' and 'hasMany' relationships. ```php belongsTo(User::class); } public function comments(): HasMany { return $this->hasMany(Comment::class); } } ``` -------------------------------- ### Generate Module from Schema (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Commands Demonstrates the schema-first development workflow using `turbo:schema` to create a schema file and then `turbo:make` to generate a module based on that schema. This approach ensures consistency and facilitates complex data structures. ```bash php artisan turbo:schema create Product --fields="name:string,price:money,category:enum" # Edit: resources/schemas/Product.yaml php artisan turbo:make Product --schema=Product --tests --factory ``` -------------------------------- ### Testing Framework Configuration in PHP Source: https://github.com/grazulex/laravel-turbomaker/wiki/Configuration Configure the testing framework to be used and related options like using database transactions and generating factories for tests. This allows customization of the testing setup. ```php return [ 'testing' => [ 'framework' => 'phpunit', 'use_database_transactions' => false, 'generate_factories_for_tests' => false, ], ]; ``` -------------------------------- ### Generate with Fragment Architecture (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture Generates fragments for a 'Post' schema using the Artisan command. The output indicates a significant performance improvement compared to traditional methods. ```bash php artisan turbo:fragments Post # ⚡ Generated in 89ms (vs 2.1s traditional) ``` -------------------------------- ### Generate Migration for Products Table in PHP Source: https://github.com/grazulex/laravel-turbomaker/wiki/Custom-Field-Types Example of a generated Laravel migration for the 'products' table. It defines decimal columns for 'price' and 'discount_amount' with appropriate precision, scale, and nullability. ```php Schema::create('products', function (Blueprint $table) { $table->decimal('price', 10, 2); $table->decimal('discount_amount', 10, 3)->nullable(); }); ``` -------------------------------- ### Scaffold Module with Relationships using Alternative Syntax (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Generates a module with relationships using the '--relationships' option, which accepts a comma-separated string of relationship definitions. This provides a more concise way to define multiple relationships. ```bash php artisan turbo:make Post --relationships="user:belongsTo,category:belongsTo,comments:hasMany" ``` -------------------------------- ### Generate Product Model with Casts in PHP Source: https://github.com/grazulex/laravel-turbomaker/wiki/Custom-Field-Types Example of a generated Eloquent model for a 'Product' entity. It includes the `fillable` properties and `casts` for decimal fields based on the schema definition. ```php class Product extends Model { protected $fillable = ['price', 'discount_amount']; protected $casts = [ 'price' => 'decimal:2', 'discount_amount' => 'decimal:3', ]; } ``` -------------------------------- ### Performance Migration Commands (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture Contains Artisan commands for benchmarking and migrating fragments between versions. It allows checking V2.0 performance, migrating to V2.1.0, and comparing performance. ```bash # Check V2.0 performance baseline php artisan turbo:benchmark --v2 # Migrate to V2.1.0 fragments php artisan turbo:migrate-fragments # Compare performance php artisan turbo:benchmark --compare ``` -------------------------------- ### Performance Benchmarks: Generation Speed Comparison Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture Compares the generation speed of the traditional V2.0 approach with the new Fragment Architecture in V2.1.0, showing significant improvements. ```bash # Traditional V2.0 Approach Blog Post Module: 2.3s E-commerce Product: 4.1s User Management: 3.7s # Fragment Architecture V2.1.0 Blog Post Module: 87ms (96% faster) E-commerce Product: 143ms (97% faster) User Management: 125ms (97% faster) ``` -------------------------------- ### Generated Form Request Validation (PHP) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Shows how Laravel TurboMaker integrates relationship handling into form request validation. This example demonstrates the validation rules for a 'StorePostRequest', including the 'user_id' field. ```php public function rules() { return [ 'title' => 'required|string|max:255', 'content' => 'required|string', 'user_id' => 'required|exists:users,id', ]; } ``` -------------------------------- ### Basic Fragment Generation Commands (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Fragment-Architecture Provides Artisan commands for generating fragments. Supports generating all fragments, specific types, or disabling caching. ```bash # Generate all fragments for a schema php artisan turbo:fragments Post # Generate specific fragment types php artisan turbo:fragments User --only=model,migration,factory # Generate with caching disabled php artisan turbo:fragments Product --no-cache ``` -------------------------------- ### Compare Code Generation Times Source: https://github.com/grazulex/laravel-turbomaker/wiki/Commands Observe the performance difference in code generation between traditional methods and using schema integration. Generating code with schema optimization (`--schema=Product`) significantly reduces execution time compared to the traditional approach. ```bash # Traditional generation (what you'll see) php artisan turbo:make Product # ⏱️ Typical time: 0.8-2.1s depending on complexity # With schema (optimized) php artisan turbo:make Product --schema=Product # ⏱️ Optimized time: 0.4-1.2s (ModelSchema integration) ``` -------------------------------- ### Generated Migration Foreign Keys (PHP) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships Illustrates how Laravel TurboMaker automatically adds foreign key columns to your database migrations. This example shows the 'create_posts_table' migration with a 'user_id' foreign key. ```php public function up() { Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('content'); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->timestamps(); }); } ``` -------------------------------- ### Generate StoreProductRequest Form Request in PHP Source: https://github.com/grazulex/laravel-turbomaker/wiki/Custom-Field-Types Example of a generated Form Request for storing products. It defines validation rules for 'price' and 'discount_amount', including required, numeric, and minimum value constraints. ```php class StoreProductRequest extends FormRequest { public function rules(): array { return [ 'price' => ['required', 'numeric', 'min:0'], 'discount_amount' => ['nullable', 'numeric', 'min:0'], ]; } } ``` -------------------------------- ### Example Validation Errors (Bash) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Schema-System Presents common validation errors encountered with Laravel Turbomaker schemas, including issues with field types, missing required properties, and invalid relationship definitions. ```bash ❌ Invalid field type 'invalid_type' for field 'title' ❌ Field 'price' must have a type ❌ Relationship 'category' must have a model ❌ Invalid relationship type 'invalid_relation' ``` -------------------------------- ### Create a Schema and Generate Module with `turbo:schema` and `turbo:make` Source: https://github.com/grazulex/laravel-turbomaker/blob/main/README.md This demonstrates schema-based development. First, a schema file is created with specified fields. Then, a module is generated using this schema definition. ```bash # Create a schema file php artisan turbo:schema create Product --fields="name:string,price:decimal,category_id:foreignId" # Generate from schema php artisan turbo:make Product --schema=Product ``` -------------------------------- ### Test Generation Script for Laravel TurboMaker Modules Source: https://github.com/grazulex/laravel-turbomaker/wiki/Examples This bash script automates the generation of tests for multiple Laravel TurboMaker modules. It iterates through a predefined array of model names (User, Post, Category, Comment) and uses the `turbo:make` command with the `--tests` and `--factory` flags to generate or update modules along with their corresponding tests and factories. The `--force` flag is used to overwrite existing files. ```bash #!/bin/bash # generate-tests.sh MODELS=("User" "Post" "Category" "Comment") for model in "${MODELS[@]}"; do echo "Generating module with tests for $model..." php artisan turbo:make "$model" --tests --factory --force done echo "All modules with tests generated!" ``` -------------------------------- ### Generate Models with Relationships (Artisan CLI) Source: https://context7.com/grazulex/laravel-turbomaker/llms.txt This section demonstrates how to generate models with various predefined relationships using the `php artisan turbo:make` command. It supports BelongsTo, HasMany, and HasOne relationships, and allows for multiple relationships to be defined simultaneously. The alternative syntax using the `--relationships` option is also shown. ```bash # BelongsTo relationship php artisan turbo:make Post --belongs-to=User # HasMany relationship php artisan turbo:make User --has-many=Post # HasOne relationship php artisan turbo:make User --has-one=Profile # Multiple relationships php artisan turbo:make Post --belongs-to=User --belongs-to=Category --has-many=Comment # Complex e-commerce relationships php artisan turbo:make Order --belongs-to=User --has-many=OrderItem --has-one=Invoice php artisan turbo:make OrderItem --belongs-to=Order --belongs-to=Product # Alternative syntax with --relationships option php artisan turbo:make Post --relationships="user:belongsTo,category:belongsTo,comments:hasMany" ``` -------------------------------- ### Generated PostFactory with Relationship (PHP) Source: https://github.com/grazulex/laravel-turbomaker/wiki/Relationships An example of a generated PostFactory.php file that includes a relationship definition, specifically setting the 'user_id' using a factory. This ensures that related models are created correctly when generating posts. ```php public function definition() { return [ 'title' => $this->faker->sentence(), 'content' => $this->faker->paragraphs(3, true), 'user_id' => User::factory(), ]; } ``` -------------------------------- ### Generate First Module with Fragment Architecture Source: https://github.com/grazulex/laravel-turbomaker/wiki/Getting-Started Creates a new module (e.g., 'Post') using the `turbo:fragments` Artisan command, leveraging the Fragment Architecture for rapid generation of various components like models, controllers, and migrations. ```bash php artisan turbo:fragments Post ``` -------------------------------- ### Managing Relationships in turbo:make Source: https://github.com/grazulex/laravel-turbomaker/wiki/Commands Define relationships between modules directly during generation using options like `--belongs-to`, `--has-one`, and `--has-many`. This streamlines the setup of relational data structures. ```bash php artisan turbo:make {name} --belongs-to={Model} --has-many={Model} # Example: Multiple relationships php artisan turbo:make OrderItem \ --belongs-to=Order \ --belongs-to=Product \ --has-one=Invoice # Example: E-commerce example php artisan turbo:make Product \ --has-many=Review \ --has-many=OrderItem \ --belongs-to=Category ``` -------------------------------- ### Name-Based Factory Generation in Laravel Turbomaker Source: https://github.com/grazulex/laravel-turbomaker/wiki/Field-Types Highlights TurboMaker's intelligent factory data generation based on field names. Provides examples for first name, email, phone, address, title, and slug. ```yaml first_name: type: string # Factory: fake()->firstName() email: type: string # Factory: fake()->unique()->safeEmail() phone: type: string # Factory: fake()->phoneNumber() address: type: string # Factory: fake()->address() title: type: string # Factory: fake()->sentence(3) slug: type: string # Factory: fake()->slug() ```