Laravel API/Scaffold/CRUD Generator (Laravel5.1) for gabrieljaime/laravel-admin-master
I enjoy creating API's and I have worked on many projects that required them. But the problem I always faced was setting up all the boilerplate code. For example each end point needs a migration, model, controller, repository, and on and on. I wanted a way to streamline this process and that is how this package was born.
This API generator allows you to use artisan commands to automatically generate all these files saving you time. Not only does it auto generate the files but it will set the namespaces.
The artisan command can generate the following items:
And your simple CRUD and APIs are ready in mere seconds.
Add the ServiceProviders to the providers array in config/app.php.
As we are using these two packages laravelcollective/html & laracasts/flash as a dependency.
so we need to add those ServiceProviders as well.
Config file (config/generator.php) contains path for all generated files
base_controller - Base Controller for all Controllers
path_migration - Path where Migration file to be generated path_model - Path where Model file to be generated path_repository - Path where Repository file to be generated path_controller - Path where Controller file to be generated path_api_controller - Path where API Controller file to be generated path_views - Path where views will be created path_request - Path where request file will be created path_routes - Path of routes.php (if you are using any custom routes file) path_api_routes - Path of api_routes.php (this file will contain all api routes)
namespace_model - Namespace of Model namespace_repository - Namespace of Repository namespace_controller - Namespace of Controller namespace_api_controller - Namespace of API Controller namespace_request - Namespace for Request
model_extend_class - Extend class of Models
api_prefix - API Prefix
api_version - API Version
use_dingo_api - Integrate APIs with dingo/api package
Publish & Initialization
Mainly, we need to do three basic things to get started.
Publish some common views like errors.blade.php & paginate.blade.php.
Publish api_routes.php which will contain all our api routes.
Init routes.php for api routes. We need to include api_routes.php into main routes.php.
php artisan gabo.generator:publish
Fire artisan command to generate API, Scaffold with CRUD views or both API as well as CRUD views.
php artisan gabo.generator:api ModelName
Generate CRUD Scaffold:
php artisan gabo.generator:scaffold ModelName
Generate CRUD Scaffold with API:
php artisan gabo.generator:scaffold_api ModelName
php artisan gabo.generator:api Project
php artisan gabo.generator:api Post
php artisan gabo.generator:scaffold Project
php artisan gabo.generator:scaffold Post
php artisan gabo.generator:scaffold_api Project
php artisan gabo.generator:scaffold_api Post
Supported HTML Field Types
Here is the list of supported field types with options:
If you want to use your own base controller or want to extend/modify default AppBaseController then you can have following options:
If you want to use another controller (recommended to extends AppBaseController with new controller) as base controller then modify base_controller value in config/generator.php
If you want to modify AppBaseController then,
Publish AppBaseController in your controllers path