julio/capyrel
Capyrel is intelligent Laravel scaffolding: it reads your database schema and auto-generates Eloquent relationships plus models, controllers, Blade views, API resources, form requests, and Pest tests. Includes model mapping, safe migration scanning, and live model updates.
Installation:
composer require julio/capyrel
No additional configuration is needed—Laravel’s auto-discovery handles registration.
First Use Case:
Run the scaffold command to generate models, controllers, and views for an existing table (e.g., User):
php artisan model:scaffold User
--dry-run to preview changes without writing files:
php artisan model:scaffold User --dry-run
Where to Look First:
app/Models/, app/Http/Controllers/, and resources/views/ for new files.User.php) to see auto-detected Eloquent relationships like hasMany, belongsTo, etc.resources/views/users/index.blade.php for embedded loops and relationship displays.Incremental Scaffolding:
php artisan model:scaffold User --models
php artisan model:scaffold User --controllers
--force to skip confirmations for automation (e.g., CI/CD):
php artisan model:scaffold --force
Database-Agnostic Workflow:
php artisan model:scaffold --connection=pgsql
API Development:
php artisan model:resources User
whenLoaded() in resources to conditionally include relationships.Testing:
php artisan model:tests User
php artisan test --filter=relationships
Livewire Integration:
php artisan model:scaffold User --livewire
Migration Safety:
php artisan migrate:safe --check
New Feature Development:
model:watch to auto-update models:
php artisan model:watch
Legacy Codebase Onboarding:
model:map to visualize the schema:
php artisan model:map --format=mermaid
Validation Rules:
php artisan model:requests Post
rules() method (e.g., add min:5 for string fields).Health Checks:
php artisan model:scaffold --health-check
Customize Generation:
config/capyrel.php or publishing the config:
php artisan vendor:publish --provider="JulioOxalis\Capyrel\CapyrelServiceProvider"
ModelGenerator, ControllerGenerator, etc., classes in app/Generators/.Seeders and Factories:
database/factories/ and reference them in generated tests:
// In UserTest.php
$user = User::factory()->create();
--factories flag to generate factories alongside models:
php artisan model:scaffold User --factories
Livewire Components:
php artisan model:scaffold User --livewire
app/Http/Livewire/User/Index.php.Policies and Events:
app/Policies/) and events (app/Events/) after scaffolding, as Capyrel does not auto-generate these.MongoDB Projects:
user_id for references).--connection=mongodb to target the correct database.Overwriting Existing Files:
--force to overwrite:
php artisan model:scaffold --force
app/Http/Controllers/UserController.php) before running --force.Circular Dependencies:
User ↔ Post ↔ User) but may generate ambiguous method names.naming_strategy in config.MongoDB Limitations:
user_id).model:map --connection=mongodb to verify relationships before scaffolding.Soft Deletes:
deleted_at columns require the SoftDeletes trait. Capyrel adds this automatically, but ensure your AppServiceProvider has:
use Illuminate\Database\Eloquent\SoftDeletes;
Livewire Component Conflicts:
User/Index.php already exists, Livewire generation may fail.--livewire with --force or manually merge components.Health Check False Positives:
config/capyrel.php.Dry-Run Mismatches:
--dry-run shows what would be generated, but actual output may differ due to:
git diff after running --dry-run.Multi-Tenant Projects:
--connection=tenant_{id} or filter tables manually.Relationships Not Detected:
model:map to verify foreign keys:
php artisan model:map --format=both
author_id vs. user_id).fk_strategy in config.Validation Rules Incorrect:
model:requests --dry-run output.varchar(255) → max:255 may conflict with existing rules.rules() method in the generated request class.Watch Mode Not Updating:
database/migrations/ is being watched (check terminal output).--interval (default: 2s).Mermaid Diagram Errors:
hasManyThrough) may not render cleanly.php artisan model:map
Pest Tests Failing:
skip() in generated tests or run with --env=testing.Custom Stubs:
vendor/julio/capyrel/src/Generators/Stubs/ to config/capyrel/stubs/.model.stub to add default scopes.Partial Generation:
php artisan model:scaffold User --views
Exclude Tables:
config/capyrel.php:
'excluded_tables' => ['migrations', 'failed_jobs'],
Livewire Props:
public $props arrayHow can I help you explore Laravel packages today?