Download the PHP package seangly/laravel-csrm without Composer
On this page you can find all versions of the php package seangly/laravel-csrm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download seangly/laravel-csrm
More information about seangly/laravel-csrm
Files in seangly/laravel-csrm
Package laravel-csrm
Short Description One command to scaffold a full Controller-Service-Repository-Model design pattern in Laravel
License MIT
Informations about the package laravel-csrm
Laravel CSRM Package - Setup Guide
Overview
The Laravel CSRM Package is a powerful generator that scaffolds a complete Controller-Service-Repository-Model design pattern in your Laravel application. It follows SOLID principles and best practices for enterprise-level Laravel development.
Requirements
- PHP: 8.1 or higher
- Laravel: 10.x or higher
- Composer: Latest version
Installation
Step 1: Install the Package via Composer
Option A: From Packagist (Production)
Option B: From Local Path (Local Development)
If you have the package code locally and want to test it:
-
Add the path repository to your
composer.json: - Then run:
Note: Don't use composer require when a path repository is configured. Instead, manually add the package to require section and run composer install or composer update.
The package will be automatically discovered and registered through Laravel's auto-discovery feature.
Step 2: Verify Installation
Check that the CSRM commands are available:
You should see:
Usage
Initial Setup
Before creating modules, set up the base CSRM structure:
This command generates:
BaseController- Base controller classBaseService- Base service classBaseRepository- Base repository classBaseRepositoryInterface- Repository interface contract
No example module is generated by default. Use php artisan csrm:make {Name} to create actual modules.
Options
The --force flag overwrites existing files without prompting.
Generate New Modules
After initial setup, create new CSRM modules:
Example
This generates the CSRM module for a Post:
app/Models/Post.php- Eloquent modeldatabase/migrations/*_create_posts_table.php- Database migrationapp/Repositories/PostRepository.php- Repository for data operationsapp/Repositories/Contracts/PostRepositoryInterface.php- Repository interfaceapp/Services/PostService.php- Business logic serviceapp/Http/Controllers/PostController.php- Web controller (default, generated with empty method bodies)
Controller Mode Options
You can generate controller variants:
--apicreatesapp/Http/Controllers/Api/*Controller.php- without
--api, controller is generated inapp/Http/Controllers/*Controller.php(web default) - By default, generated controller methods are empty and do not include repository/service scaffolding
- If both
--apiand--webare provided together, the command fails and asks you to choose one.
Selective Generation
Generate only specific components:
Available Options
model- Eloquent model (implemented)migration- Database migration (implemented)repository- Repository class (implemented)service- Service class (implemented)controller- HTTP controller (implemented)
Current Generator Status
Currently implemented:
modelmigrationrepositoryservicecontroller
Overwrite Existing Files
Directory Structure
After running csrm:install, your application structure will be:
Design Pattern Explanation
Repository Layer (Data Access)
Handles data access, including queries and persistence operations.
BaseRepositoryInterface methods:
all()- Get all recordspaginate()- Paginate recordsfind()- Find by IDfindOrFail()- Find by ID or throw exceptionquery()- Get query builder for complex queriesfindBy()- Find by field and valuefindAllBy()- Find all by field and valuecreate()- Create new recordupdate()- Update existing recorddelete()- Delete record
Service Layer (Business Logic & Actions)
Handles business logic and orchestrates action flows. It calls repository methods for persistence.
Architecture Summary
Configuration
Publishing Assets
To customize stubs, publish them to your project:
Customized stubs will be placed in stubs/csrm/ and will be used for future generation.
Repository Binding
The package automatically binds repositories in AppServiceProvider:
You can inject the interface in your service or controller:
Next Steps
1. Run Database Migrations
After installation or creating new modules:
2. Add Routes Manually
The package does not auto-generate route files for new modules. Add routes manually as needed, for example:
3. Customize Generated Code
The generated files are starting points. Customize them for your specific business logic:
- Add additional methods to repositories
- Implement complex business logic in services
- Implement relationships in models
Common Workflows
Create a Complete Module
Add Additional Functionality
After generating a module, enhance the service layer:
Use Repository Interface in Multiple Services
Troubleshooting
Commands Not Showing
Verify the package is installed:
Clear cached services:
Regenerate autoloaders:
Migration Errors
Ensure your database is properly configured in .env:
Class Not Found Errors
Clear application cache:
Contributing & Support
For issues, feature requests, or contributions, visit the GitHub repository:
https://github.com/Chhounseangly/laravel-csrm
License
This package is licensed under the MIT license. See the LICENSE file for details.