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.
This documentation provides details on the custom artisan commands available in the Laravel Easy Dev package.
The make:crud command generates a complete set of files for CRUD operations including a model, migration, controller, form requests, and optionally a repository pattern implementation.
php artisan make:crud Post
This command will create:
Post model with migrationStorePostRequest and UpdatePostRequest form request classes with intelligent validation rulesPostController with all necessary CRUD methods| Option | Description |
|---|---|
--api |
Generate an API controller that returns JSON responses |
--routes |
Automatically add resource routes to the routes file |
--force |
Overwrite existing files without prompting |
--relations |
Define relationships for the model (format: "model:type,model:type") |
Basic CRUD generation
php artisan make:crud Product
API CRUD with routes
php artisan make:crud Order --api --routes
CRUD with predefined relationships
php artisan make:crud Invoice --relations="user:belongsTo,items:hasMany"
The command automatically analyzes your migration file to determine model fields and generates appropriate validation rules based on field names:
email validationmin:8 validationurl validationdate validationboolean validationnumeric validationinteger validationWhen enabled (through interactive prompt):
The make:model-relation command allows you to manually define and add relationships to an existing model.
php artisan make:model-relation Post --relations="user:belongsTo,comment:hasMany,tag:belongsToMany"
This command will add the specified relationships to the Post model:
user() method with a belongsTo relationshipcomments() method with a hasMany relationshiptags() method with a belongsToMany relationship| Option | Description |
|---|---|
--relations |
Define relationships for the model (format: "model:type,model:type") |
belongsTo - Creates a relationship where this model "belongs to" another modelhasMany - Creates a one-to-many relationshiphasOne - Creates a one-to-one relationshipbelongsToMany - Creates a many-to-many relationship through a pivot tableAdding a belongsTo and hasMany relationship
php artisan make:model-relation Product --relations="category:belongsTo,review:hasMany"
Adding a many-to-many relationship
php artisan make:model-relation Post --relations="tag:belongsToMany"
The command:
The model:sync-relations command automatically detects and sets up Eloquent relationships between your models based on database schema and migration files. This is the most powerful relationship command that can analyze your application's structure.
To sync relationships for a single model:
php artisan model:sync-relations Post
This command will:
| Option | Description |
|---|---|
--all |
Sync relationships for all models in your application |
--morph-targets |
Comma-separated list of models to apply polymorphic relationships to |
To scan and update relationships for all models in your application:
php artisan model:sync-relations --all
This will process every model in your app/Models directory, detecting and adding relationships automatically.
The command can detect and set up polymorphic relationships from your migrations. For example, if you have an Image model with a polymorphic imageable relationship:
// Migration example
Schema::create('images', function (Blueprint $table) {
$table->id();
$table->string('url');
$table->morphs('imageable'); // Creates imageable_id and imageable_type columns
$table->timestamps();
});
Running:
php artisan model:sync-relations Image
Will add:
imageable() method with morphTo() relation to the Image modelimages() methods with morphMany() relation to potential related modelsThe command will interactively ask which models should have the polymorphic relationship added.
When working with polymorphic relationships, you can specify which models should receive the polymorphic relations using the --morph-targets option:
php artisan model:sync-relations Image --morph-targets="Post,User"
This will only add the images() method to the Post and User models, without prompting for each model.
The command also handles unary (self-referential) relationships, such as categories with parent-child relationships:
// Migration example
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->unsignedBigInteger('parent_id')->nullable();
$table->foreign('parent_id')->references('id')->on('categories');
$table->timestamps();
});
Running:
php artisan model:sync-relations Category
Will add:
parent() method to access the parent categorychildren() method to access child categoriesExample 1: Basic Foreign Key Relationship
Migration:
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content');
$table->foreignId('user_id')->constrained();
$table->timestamps();
});
Command:
php artisan model:sync-relations Post
Results:
user() method to Post modelposts() method to User modelExample 2: Many-to-Many Relationship
Migration:
Schema::create('post_tag', function (Blueprint $table) {
$table->foreignId('post_id')->constrained();
$table->foreignId('tag_id')->constrained();
$table->primary(['post_id', 'tag_id']);
});
Command:
php artisan model:sync-relations Post
Results:
tags() method to Post modelposts() method to Tag modelExample 3: Polymorphic Relationship
Migration:
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->text('body');
$table->morphs('commentable');
$table->timestamps();
});
Command:
php artisan model:sync-relations Comment --morph-targets="Post,Video"
Results:
commentable() method to Comment model (correctly named without _type suffix)comments() method to Post modelcomments() method to Video model| Feature | model:sync-relations |
make:model-relation |
make:crud --relations |
|---|---|---|---|
| Automatic detection | ✅ Uses database schema & migrations | ❌ Requires manual specification | ⚠️ Only detects basic relationships |
| Multiple models | ✅ Can process all models at once | ❌ One model at a time | ❌ Only for the model being created |
| Bidirectional relationships | ✅ Creates both sides of relationships | ❌ Only adds to one model | ❌ Only adds to one model |
| Polymorphic support | ✅ Full detection and configuration | ❌ Not supported | ❌ Not supported |
| Requires existing tables | ⚠️ Falls back to migrations if no tables | ✅ Only needs model file | ✅ Only needs model file |
If the command reports that tables are not found in the database, make sure:
If the command says "Relationship method already exists", the relationship is already defined in the model. The command will skip adding it to avoid duplicates.
If related models don't exist, create them first using:
php artisan make:model ModelName
The model:sync-relations command supports MySQL, PostgreSQL, and SQLite database drivers. Each driver has specific methods for detecting relationships.
How can I help you explore Laravel packages today?