SimpleCrudGenerator is a package designed to easily generate CRUD operations for your Laravel applications. With one command, you can generate models, migrations, controllers, services, and requests based on a database table name.
You can install the package via Composer:
Run the following Composer command in your Laravel project:
composer require ranitachi/simple-crud-generator
In most cases, the service provider will be automatically discovered by Laravel. However, if you need to manually add it, include the service provider in your config/app.php
file:
'providers' => [
// Other service providers
Fcn\SimpleCrudGenerator\SimpleCrudGeneratorServiceProvider::class,
];
Once installed, you can generate the CRUD files using the following Artisan command:
php artisan make:simple-crud {table_name}
Replace {table_name}
with the name of the database table for which you want to generate the CRUD files.
For example:
php artisan make:simple-crud posts
This will generate the following:
- Migration file for the
posts
table. - Model with
SoftDeletes
. - Controller with basic CRUD operations.
- Service to handle business logic.
- Request class for validation.
After running the generator command, you can immediately start using the generated files.
-
Model: The model will be located at
app/Models/Post.php
if your table is namedposts
. -
Controller: The controller will be generated in
app/Http/Controllers/PostController.php
. -
Service: The service class will be in
app/Services/PostService.php
, responsible for handling business logic. -
Request: The request file will be generated at
app/Http/Requests/PostRequest.php
and can be used for validation.
You can define the route in routes/web.php
to use the generated controller:
Route::resource('posts', App\Http\Controllers\PostController::class);
- Automatically generates migration, model, controller, request, and service files based on a given table name.
- Supports soft deletes by default in generated models.
- Generates RESTful controllers with all CRUD methods.
- Includes basic validation via Request classes.
Contributions are welcome! Please feel free to submit a Pull Request.
The MIT License (MIT). Please see License File for more information.