The Laravel API SOLID project includes powerful Artisan commands for rapid development with clean architecture patterns and automated route management.
Generate complete CRUD structures with repositories, services, and optional resource folders.
php artisan make:structure {model} {--no-resource} {--only=}# Generate full CRUD structure
php artisan make:structure PostSelective CRUD Generation
# Generate specific CRUD methods only
php artisan make:structure Post --only=create,read,update
php artisan make:structure Post --only=read,update
php artisan make:structure Post --only=create,deleteSkip Resource Folders
# Skip resource folder generation
php artisan make:structure Post --no-resourceCombined Options
# Combine options for maximum flexibility
php artisan make:structure Post --only=read,update --no-resourceapp/
├── Http/
│ └── Resources/
│ └── Post/
│ ├── Admin/ # Admin-specific resources
│ └── Api/ # API-specific resources
├── Services/
│ └── Post/
│ ├── PostCreateService.php
│ ├── PostReadService.php
│ ├── PostUpdateService.php
│ └── PostDeleteService.php
└── Repositories/
└── PostRepository.php
Create route groups with middleware and automatic registration in the application bootstrap.
php artisan make:route-group {name} {--prefix=} {--middleware=}# Generate route group with default settings
php artisan make:route-group Admin# Custom prefix and middleware
php artisan make:route-group Admin --prefix=admin --middleware=admin
# API route group
php artisan make:route-group Api --prefix=api/v1 --middleware=api
# Public route group
php artisan make:route-group Public --prefix=public --middleware=web- Route File:
routes/{name}.php - Middleware Registration: Added to application configuration
- Route Group Registration: Automatically registered in
bootstrap/app.php
Original CRUD generation command with resource folder support.
php artisan generate:crud Post- 🎯 Selective Generation: Choose specific CRUD methods to generate
- 📁 Optional Resources: Skip resource folder creation when not needed
- 🔧 Modern PHP: Constructor property promotion (PHP 8.0+)
- 📝 Clean Code: Consistent naming conventions and structure
- ⚡ Rapid Development: Generate complete CRUD structures in seconds
- 🏗️ SOLID Architecture: Repository pattern with service layer separation
- 🚀 Automatic Registration: Routes are automatically registered
- 🛡️ Middleware Integration: Custom middleware assignment
- 📁 Organized Structure: Clean route file organization
- 🔧 Flexible Configuration: Customizable prefix and middleware
- 📝 Template System: Uses customizable stub templates
<?php
namespace App\Services\{{model}};
use App\Repositories\{{model}}Repository;
class {{className}}Service
{
public function __construct(private {{model}}Repository ${{lowerModel}}Repository) {}
public function {{lowerMethod}}(array $data)
{
// Your {{lowerMethod}} logic goes here
}
}<?php
namespace App\Repositories;
use App\Models\{{model}};
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
class {{model}}Repository extends BaseRepository
{
/**
* Specify Model class name
*
* @return string
*/
public function model()
{
return {{model}}::class;
}
/**
* Boot up the repository, pushing criteria
*/
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
}<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| {{name}} Routes
|--------------------------------------------------------------------------
|
| Here is where you can register {{name}} routes for your application.
| These routes are loaded by the RouteServiceProvider within a group which
| contains the "{{middleware}}" middleware group.
|
*/
Route::get('/', function () {
return response()->json([
'message' => 'Welcome to {{name}} API',
'status' => 'success'
]);
});# Generate complete blog post structure
php artisan make:structure Post
# This creates:
# - app/Repositories/PostRepository.php
# - app/Services/Post/PostCreateService.php
# - app/Services/Post/PostReadService.php
# - app/Services/Post/PostUpdateService.php
# - app/Services/Post/PostDeleteService.php
# - app/Http/Resources/Post/Admin/
# - app/Http/Resources/Post/Api/# Generate user services without resource folders
php artisan make:structure User --no-resource
# This creates:
# - app/Repositories/UserRepository.php
# - app/Services/User/UserCreateService.php
# - app/Services/User/UserReadService.php
# - app/Services/User/UserUpdateService.php
# - app/Services/User/UserDeleteService.php# Generate only read operations for products
php artisan make:structure Product --only=read
# This creates:
# - app/Repositories/ProductRepository.php
# - app/Services/Product/ProductReadService.php
# - app/Http/Resources/Product/Admin/
# - app/Http/Resources/Product/Api/# Create admin route group
php artisan make:route-group Admin --prefix=admin --middleware=admin
# This creates:
# - routes/admin.php
# - Registers middleware group 'admin'
# - Adds route group to bootstrap/app.php<?php
namespace App\Services\Post;
use App\Repositories\PostRepository;
class PostCreateService
{
public function __construct(private PostRepository $postRepository) {}
public function create(array $data)
{
// Your create logic goes here
return $this->postRepository->create($data);
}
}<?php
namespace App\Repositories;
use App\Models\Post;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
class PostRepository extends BaseRepository
{
public function model()
{
return Post::class;
}
public function boot()
{
$this->pushCriteria(app(RequestCriteria::class));
}
}<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
*/
Route::get('/', function () {
return response()->json([
'message' => 'Welcome to Admin API',
'status' => 'success'
]);
});
// Add your admin routes here
Route::apiResource('posts', PostController::class);You can customize the generated code by modifying the stub files:
- Service Stub:
stubs/service.stub - Repository Stub:
stubs/repository.stub - Route Group Stub:
stubs/route-group.stub
{{model}}- Model name (e.g., "Post"){{className}}- Full class name (e.g., "PostCreateService"){{method}}- CRUD method (e.g., "Create"){{lowerMethod}}- Lowercase method (e.g., "create"){{lowerModel}}- Lowercase model (e.g., "post"){{name}}- Route group name{{middleware}}- Middleware name
$ php artisan make:structure Post --only=create,read
Repository, Service files, Resource folders (Admin, Api) created for Post with methods: create, read.
$ php artisan make:structure User --no-resource
Repository, Service files created for User with methods: create, read, update, delete.
$ php artisan make:route-group Admin --prefix=admin
✅ Route group 'Admin' created successfully!
📄 Using custom stub from stubs/route-group.stub
✅ Route file 'admin.php' created successfully.
✅ Route group 'Admin' registered in bootstrap/app.phpclass PostCreateServiceTest extends TestCase
{
public function test_creates_post_successfully()
{
$mockRepository = Mockery::mock(PostRepository::class);
$service = new PostCreateService($mockRepository);
$postData = [
'title' => 'Test Post',
'content' => 'Test content'
];
$mockRepository->shouldReceive('create')
->once()
->with($postData)
->andReturn(new Post($postData));
$result = $service->create($postData);
$this->assertInstanceOf(Post::class, $result);
}
}class AdminRoutesTest extends TestCase
{
public function test_admin_index_route()
{
$response = $this->get('/admin/');
$response->assertStatus(200)
->assertJson([
'message' => 'Welcome to Admin API',
'status' => 'success'
]);
}
}- Start Small: Use
--onlyflag for specific operations - Skip Unnecessary: Use
--no-resourcewhen resources aren't needed - Consistent Naming: Use PascalCase for model names
- Test Generated Code: Always test generated services and repositories
- Follow Conventions: Stick to Laravel naming conventions
- Add Business Logic: Implement actual logic in generated service methods
- Handle Exceptions: Add proper error handling
- Document Methods: Add PHPDoc comments to generated methods
- Group Related Routes: Use route groups for related functionality
- Apply Middleware: Use appropriate middleware for security
- Version APIs: Consider versioning for public APIs
- Document Endpoints: Maintain API documentation
- Controller Generation: Automatic controller creation with service injection
- Request Validation: Generate form request classes
- API Documentation: Automatic OpenAPI/Swagger documentation
- Test Generation: Automatic test class generation
- Migration Integration: Generate migrations alongside models
- Seeder Generation: Create seeders for generated models
- Custom Service Templates: Different templates for different use cases
- Repository Variants: Templates for different repository patterns
- Resource Templates: Pre-built API resource templates
- Controller Templates: Various controller patterns