├── .gitignore
├── LICENSE
├── README.md
├── Upgrade_Guide.md
├── composer.json
├── config
└── generator.php
├── installation.md
├── samples
└── fields.json
├── src
├── .gitignore
└── Mitul
│ ├── Controller
│ └── AppBaseController.php
│ └── Generator
│ ├── CommandData.php
│ ├── Commands
│ ├── APIGeneratorCommand.php
│ ├── BaseCommand.php
│ ├── PublisherCommand.php
│ ├── ScaffoldAPIGeneratorCommand.php
│ └── ScaffoldGeneratorCommand.php
│ ├── Errors.php
│ ├── File
│ └── FileHelper.php
│ ├── FormFieldsGenerator.php
│ ├── GeneratorServiceProvider.php
│ ├── Generators
│ ├── API
│ │ └── APIControllerGenerator.php
│ ├── Common
│ │ ├── MigrationGenerator.php
│ │ ├── ModelGenerator.php
│ │ ├── RepositoryGenerator.php
│ │ ├── RequestGenerator.php
│ │ └── RoutesGenerator.php
│ ├── GeneratorProvider.php
│ └── Scaffold
│ │ ├── ViewControllerGenerator.php
│ │ └── ViewGenerator.php
│ ├── SchemaGenerator.php
│ ├── TemplatesHelper.php
│ └── Utils
│ ├── GeneratorUtils.php
│ └── TableFieldsGenerator.php
├── templates
├── api
│ └── Controller.stub
├── common
│ ├── Migration.stub
│ ├── Model.stub
│ └── Repository.stub
├── controller
│ └── AppBaseController.stub
├── routes
│ ├── api_routes.stub
│ ├── api_routes_group.stub
│ ├── dingo_api_routes_group.stub
│ └── scaffold_routes.stub
└── scaffold
│ ├── Controller.stub
│ ├── requests
│ ├── CreateRequest.stub
│ └── UpdateRequest.stub
│ └── views
│ ├── create.blade.stub
│ ├── edit.blade.stub
│ ├── field.blade.stub
│ ├── fields.blade.stub
│ ├── index.blade.stub
│ ├── paginate.blade.stub
│ ├── show.blade.stub
│ ├── show_field.blade.stub
│ └── table.blade.stub
└── views
└── common
├── errors.blade.php
└── paginate.blade.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.lock
3 | .idea
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Mitul Golakya
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Laravel API/Scaffold/CRUD Generator
2 | =======================
3 | [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator)
4 |
5 | # THIS PACKAGE IS DEPRECATED. USE NEW ONE FROM [HERE](https://github.com/InfyOmLabs/laravel-generator)
6 |
7 | # IF YOU STILL WANT TO USE THIS PACKAGE. [HERE](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/installation.md) ARE THE INSTALLATION STEPS.
8 |
--------------------------------------------------------------------------------
/Upgrade_Guide.md:
--------------------------------------------------------------------------------
1 | Laravel API/Scaffold/CRUD Generator Upgrade Guide (Laravel5)
2 | =======================
3 |
4 | Upgrade Guide from 1.2 to 1.3
5 | -------------------------------------
6 |
7 | We are no longer using our own ```APIExceptionsHandler``` to send API fail responses and using Laravel's own ```HttpResponseException``` to overcome ```App\Exceptions\Handler``` overwrite problem.
8 |
9 | So we removed all extra Exception files. so you need to remove those things from your API Controllers.
10 |
11 | 1. In all your API Controllers and find ```throw new RecordNotFoundException```.
12 |
13 | 2. Replace it with ```$this->throwRecordNotFoundException```.
14 |
15 | 3. Remove use statements
16 |
17 | use Mitul\Generator\Exceptions\AppValidationException;
18 | use Mitul\Generator\Exceptions\RecordNotFoundException;
19 |
20 | 4. Remove throw statement from PHPDoc Blocks of functions
21 |
22 | @throws AppValidationException
23 | @throws RecordNotFoundException
24 |
25 | 5. Enjoy Upgrade :)
26 |
27 | Upgrade Guide from 1.0 to 1.1 or 1.2
28 | -------------------------------------
29 |
30 | 1. Take a backup of your ```config/generator.php```
31 |
32 | 2. Delete your ```config/generator.php```
33 |
34 | 3. Change version in composer.json
35 |
36 | "require": {
37 | "mitulgolakiya/laravel-api-generator": "1.2.*"
38 | }
39 |
40 | 4. Run composer update.
41 |
42 | 5. Run publish command again.
43 |
44 | php artisan vendor:publish --provider="Mitul\Generator\GeneratorServiceProvider"
45 |
46 | 6. Replace your custom paths again in ```config/generator.php```.
47 |
48 | 7. Enjoy Upgrade :)
49 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mitulgolakiya/laravel-api-generator",
3 | "description": "Laravel API/Scaffold/CRUD Generator from just one command with including Controller, Repository, Model, Migrations, routes.php update.",
4 | "keywords": [
5 | "laravel",
6 | "api",
7 | "model",
8 | "migration",
9 | "scaffold",
10 | "CRUD",
11 | "generator"
12 | ],
13 | "license": "MIT",
14 | "authors": [
15 | {
16 | "name": "Mitul Golakiya",
17 | "email": "me@mitul.me"
18 | }
19 | ],
20 | "require": {
21 | "php": ">=5.5.9",
22 | "illuminate/support": "5.2.*"
23 | },
24 | "autoload": {
25 | "psr-4": {
26 | "Mitul\\": "src/Mitul/"
27 | }
28 | },
29 | "suggest": {
30 | "doctrine/dbal": "Required to use generator from existing table.",
31 | "infyomlabs/laravel-generator": "This package is deprecated. we recommend to use this package instead of current package."
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/config/generator.php:
--------------------------------------------------------------------------------
1 | 'Mitul\Controller\AppBaseController',
15 |
16 | /*
17 | |--------------------------------------------------------------------------
18 | | Path for classes
19 | |--------------------------------------------------------------------------
20 | |
21 | | All Classes will be created on these relevant path
22 | |
23 | */
24 |
25 | 'path_migration' => base_path('database/migrations/'),
26 |
27 | 'path_model' => app_path('Models/'),
28 |
29 | 'path_repository' => app_path('Libraries/Repositories/'),
30 |
31 | 'path_controller' => app_path('Http/Controllers/'),
32 |
33 | 'path_api_controller' => app_path('Http/Controllers/API/'),
34 |
35 | 'path_views' => base_path('resources/views/'),
36 |
37 | 'path_request' => app_path('Http/Requests/'),
38 |
39 | 'path_routes' => app_path('Http/routes.php'),
40 |
41 | 'path_api_routes' => app_path('Http/api_routes.php'),
42 |
43 | /*
44 | |--------------------------------------------------------------------------
45 | | Namespace for classes
46 | |--------------------------------------------------------------------------
47 | |
48 | | All Classes will be created with these namespaces
49 | |
50 | */
51 |
52 | 'namespace_model' => 'App\Models',
53 |
54 | 'namespace_repository' => 'App\Libraries\Repositories',
55 |
56 | 'namespace_controller' => 'App\Http\Controllers',
57 |
58 | 'namespace_api_controller' => 'App\Http\Controllers\API',
59 |
60 | 'namespace_request' => 'App\Http\Requests',
61 |
62 | /*
63 | |--------------------------------------------------------------------------
64 | | Model extend
65 | |--------------------------------------------------------------------------
66 | |
67 | | Model extend Configuration.
68 | | By default Eloquent model will be used.
69 | | If you want to extend your own custom model then you can specify "model_extend" => true and "model_extend_namespace" & "model_extend_class".
70 | |
71 | | e.g.
72 | | 'model_extend' => true,
73 | | 'model_extend_namespace' => 'App\Models\AppBaseModel as AppBaseModel',
74 | | 'model_extend_class' => 'AppBaseModel',
75 | |
76 | */
77 |
78 | 'model_extend_class' => 'Illuminate\Database\Eloquent\Model',
79 |
80 | /*
81 | |--------------------------------------------------------------------------
82 | | API routes prefix
83 | |--------------------------------------------------------------------------
84 | |
85 | | By default "api" will be prefix
86 | |
87 | */
88 |
89 | 'api_prefix' => 'api',
90 |
91 | 'api_version' => 'v1',
92 |
93 | /*
94 | |--------------------------------------------------------------------------
95 | | dingo API integration
96 | |--------------------------------------------------------------------------
97 | |
98 | | By default dingo API Integration will not be enabled. Dingo API is in beta.
99 | |
100 | */
101 |
102 | 'use_dingo_api' => false,
103 |
104 | ];
105 |
--------------------------------------------------------------------------------
/installation.md:
--------------------------------------------------------------------------------
1 | Laravel API/Scaffold/CRUD Generator
2 | =======================
3 | [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator) [](https://packagist.org/packages/mitulgolakiya/laravel-api-generator)
4 |
5 | ### Version Compability
6 |
7 | Laravel | Branch
8 | :---------|:------------
9 | 5.0 | [1.3](https://github.com/mitulgolakiya/laravel-api-generator/tree/1.3)
10 | 5.1.* | [1.4](https://github.com/mitulgolakiya/laravel-api-generator/tree/1.4)
11 | 5.2.* | [master](https://github.com/mitulgolakiya/laravel-api-generator)
12 |
13 | 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.
14 |
15 | 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.
16 |
17 | The artisan command can generate the following items:
18 | * Migration File
19 | * Model
20 | * Repository
21 | * Controller
22 | * View
23 | * index.blade.php
24 | * table.blade.php
25 | * show.blade.php
26 | * show_fields.blade.php
27 | * create.blade.php
28 | * edit.blade.php
29 | * fields.blade.php
30 | * adjusts routes.php
31 |
32 | And your simple CRUD and APIs are ready in mere seconds.
33 |
34 | Here is the full documentation.
35 |
36 | [Upgrade Guide](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/Upgrade_Guide.md).
37 |
38 | # Documentation is in process...
39 |
40 | Documentation
41 | --------------
42 |
43 | 1. [Installation](#installation)
44 | 2. [Configuration](#configuration)
45 | 3. [Publish & Initialization](#publish--initialization)
46 | 4. [Generator](#generator)
47 | 5. [Supported Field Types](#supported-field-types)
48 | 5. [Customization](#customization)
49 | 1. [Base Controller](#base-controller)
50 | 2. [Customize Templates](#customize-templates)
51 | 3. [Dingo API Integration](#dingo-api-integration)
52 | 6. [Options](#options)
53 | 1. [Paginate Records](#paginate-records)
54 | 2. [Model Soft Deletes](#model-soft-deletes)
55 | 3. [Fields From File](#fields-from-file)
56 | 4. [Custom Table Name](#custom-table-name)
57 | 5. [Skip Migration](#skip-migration)
58 | 6. [Remember Token](#remember-token)
59 | 7. [Generator from existing tables](#generator-from-existing-tables)
60 |
61 | ## Installation
62 |
63 | 1. Add this package to your composer.json:
64 |
65 | "require": {
66 | "laracasts/flash": "~1.3",
67 | "laravelcollective/html": "5.2.*",
68 | "bosnadev/repositories": "dev-master",
69 | "mitulgolakiya/laravel-api-generator": "dev-master"
70 | }
71 |
72 | 2. Run composer update
73 |
74 | composer update
75 |
76 | 3. Add the ServiceProviders to the providers array in ```config/app.php```.
77 | As we are using these two packages [laravelcollective/html](https://github.com/LaravelCollective/html) & [laracasts/flash](https://github.com/laracasts/flash) as a dependency.
78 | so we need to add those ServiceProviders as well.
79 |
80 | Collective\Html\HtmlServiceProvider::class,
81 | Laracasts\Flash\FlashServiceProvider::class,
82 | Mitul\Generator\GeneratorServiceProvider::class,
83 |
84 | Also for convenience, add these facades in alias array in ```config/app.php```.
85 |
86 | 'Form' => Collective\Html\FormFacade::class,
87 | 'Html' => Collective\Html\HtmlFacade::class,
88 | 'Flash' => Laracasts\Flash\Flash::class
89 |
90 | ## Configuration
91 |
92 | Publish Configuration file ```generator.php```.
93 |
94 | php artisan vendor:publish --provider="Mitul\Generator\GeneratorServiceProvider"
95 |
96 | Config file (```config/generator.php```) contains path for all generated files
97 |
98 | ```base_controller``` - Base Controller for all Controllers
99 |
100 | ```path_migration``` - Path where Migration file to be generated
101 | ```path_model``` - Path where Model file to be generated
102 | ```path_repository``` - Path where Repository file to be generated
103 | ```path_controller``` - Path where Controller file to be generated
104 | ```path_api_controller``` - Path where API Controller file to be generated
105 | ```path_views``` - Path where views will be created
106 | ```path_request``` - Path where request file will be created
107 | ```path_routes``` - Path of routes.php (if you are using any custom routes file)
108 | ```path_api_routes``` - Path of api_routes.php (this file will contain all api routes)
109 |
110 | ```namespace_model``` - Namespace of Model
111 | ```namespace_repository``` - Namespace of Repository
112 | ```namespace_controller``` - Namespace of Controller
113 | ```namespace_api_controller``` - Namespace of API Controller
114 | ```namespace_request``` - Namespace for Request
115 |
116 | ```model_extend_class``` - Extend class of Models
117 |
118 | ```api_prefix``` - API Prefix
119 | ```api_version``` - API Version
120 |
121 | ```use_dingo_api``` - Integrate APIs with dingo/api package
122 |
123 | ## Publish & Initialization
124 |
125 | Mainly, we need to do three basic things to get started.
126 | 1. Publish some common views like ```errors.blade.php``` & ```paginate.blade.php```.
127 | 2. Publish ```api_routes.php``` which will contain all our api routes.
128 | 3. Init ```routes.php``` for api routes. We need to include ```api_routes.php``` into main ```routes.php```.
129 |
130 | php artisan mitul.generator:publish
131 |
132 | ## Generator
133 |
134 | Fire artisan command to generate API, Scaffold with CRUD views or both API as well as CRUD views.
135 |
136 | Generate API:
137 |
138 | php artisan mitul.generator:api ModelName
139 |
140 | Generate CRUD Scaffold:
141 |
142 | php artisan mitul.generator:scaffold ModelName
143 |
144 | Generate CRUD Scaffold with API:
145 |
146 | php artisan mitul.generator:scaffold_api ModelName
147 |
148 | e.g.
149 |
150 | php artisan mitul.generator:api Project
151 | php artisan mitul.generator:api Post
152 |
153 | php artisan mitul.generator:scaffold Project
154 | php artisan mitul.generator:scaffold Post
155 |
156 | php artisan mitul.generator:scaffold_api Project
157 | php artisan mitul.generator:scaffold_api Post
158 |
159 | Here is the sample [fields input json](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/samples/fields.json)
160 |
161 | ## Supported HTML Field Types
162 |
163 | Here is the list of supported field types with options:
164 | * text
165 | * textarea
166 | * password
167 | * email
168 | * file
169 | * checkbox
170 | * radio:male,female,option3,option4
171 | * number
172 | * date
173 | * select:India,USA
174 |
175 | ## Customization
176 |
177 | ### Base Controller
178 |
179 | If you want to use your own base controller or want to extend/modify default AppBaseController then you can have following options:
180 |
181 | 1. 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```
182 |
183 | 2. If you want to modify AppBaseController then,
184 |
185 | 1. Publish AppBaseController in your controllers path
186 |
187 | php artisan mitul.generator:publish --baseController
188 |
189 | 2. Modify the content of ```AppBaseController.php``` and set it as a ```base_controller``` in ```config/generator.php```
190 |
191 | ### Customize Templates
192 |
193 | To use your own custom templates,
194 |
195 | 1. Publish templates to ```/resources/api-generator-templates```
196 |
197 | php artisan mitul.generator:publish --templates
198 |
199 | 2. Leave only those templates that you want to change. Remove the templates that do not plan to change.
200 |
201 | ## Options
202 |
203 | ### Paginate Records
204 |
205 | To paginate records, you can specify paginate option,
206 | e.g.
207 |
208 | php artisan mitul.generator:api Post --paginate=10
209 |
210 | ### Model Soft Deletes
211 |
212 | To use SoftDelete, use softDelete option,
213 |
214 | php artisan mitul.generator:api Post --softDelete
215 |
216 | ### Fields From File
217 |
218 | If you want to pass fields from file then you can create fields json file and pass it via command line. Here is the sample [fields.json](https://github.com/mitulgolakiya/laravel-api-generator/blob/master/samples/fields.json)
219 |
220 | You have to pass option ```--fieldsFile=absolute_file_path_or_path_from_base_directory``` with command. e.g.
221 |
222 | php artisan mitul.generator:scaffold_api Post --fieldsFile="/Users/Mitul/laravel-api-generator/fields.json"
223 | php artisan mitul.generator:scaffold_api Post --fieldsFile="fields.json"
224 |
225 | ### Custom Table Name
226 |
227 | You can also specify your own custom table name by,
228 |
229 | php artisan mitul.generator:api Post --tableName=custom_table_name
230 |
231 | ### Skip Migration
232 |
233 | You can also skip migration generation,
234 |
235 | php artisan mitul.generator:api Post --skipMigration
236 |
237 | ### Remember Token
238 |
239 | To generate rememberToken field in migration file,
240 |
241 | php artisan mitul.generator:api Post --rememberToken
242 |
243 | ## Generator from existing tables
244 |
245 | To use generator with existing table, you can specify ```--fromTable``` option. ```--tableName``` option is required and you need to specify table name.
246 |
247 | Just make sure, you have installed ```doctrine/dbal``` package.
248 |
249 | **Limitation:** As of now it is not fully working (work is in progress). It will not create migration file. You need to tweak some of the things in your generated files like timestamps, primary key etc.
250 |
251 | php artisan mitul.generator:api Post --fromTable --tableName=posts
252 |
253 | Credits
254 | --------
255 |
256 | This API Generator is created by [Mitul Golakiya](https://github.com/mitulgolakiya).
257 |
258 | **Bugs & Forks are welcomed :)**
259 |
--------------------------------------------------------------------------------
/samples/fields.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "field":"title:string",
4 | "type":"text",
5 | "validations": "required"
6 | },
7 | {
8 | "field":"body:text",
9 | "type":"textarea",
10 | "validations": ""
11 | },
12 | {
13 | "field":"password:string",
14 | "type":"password",
15 | "validations": ""
16 | },
17 | {
18 | "field":"email:string",
19 | "type":"email",
20 | "validations": ""
21 | },
22 | {
23 | "field":"profile:string",
24 | "type":"file",
25 | "validations": ""
26 | },
27 | {
28 | "field":"remember:boolean",
29 | "type":"checkbox",
30 | "validations": ""
31 | },
32 | {
33 | "field":"gender:integer",
34 | "type":"radio:male,female",
35 | "validations": ""
36 | },
37 | {
38 | "field":"order:integer",
39 | "type":"number",
40 | "validations": ""
41 | },
42 | {
43 | "field":"birth_date:timestamp",
44 | "type":"date",
45 | "validations": ""
46 | },
47 | {
48 | "field":"location:string",
49 | "type":"select:Surat,Mumbai",
50 | "validations": ""
51 | }
52 | ]
--------------------------------------------------------------------------------
/src/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
--------------------------------------------------------------------------------
/src/Mitul/Controller/AppBaseController.php:
--------------------------------------------------------------------------------
1 | getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);
23 |
24 | if ($validator->fails()) {
25 | throw new HttpException(400, json_encode($validator->errors()->getMessages()));
26 | }
27 | }
28 |
29 | public function makeResponse($result, $message)
30 | {
31 | return [
32 | 'data' => $result,
33 | 'message' => $message,
34 | ];
35 | }
36 |
37 | public function sendResponse($result, $message)
38 | {
39 | return Response::json($this->makeResponse($result, $message));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/CommandData.php:
--------------------------------------------------------------------------------
1 | commandObj = $commandObj;
58 | $this->commandType = $commandType;
59 | $this->fileHelper = new FileHelper();
60 | $this->templatesHelper = new TemplatesHelper();
61 | }
62 |
63 | public function initVariables()
64 | {
65 | $this->modelNamePlural = Str::plural($this->modelName);
66 | $this->modelNameCamel = Str::camel($this->modelName);
67 | $this->modelNamePluralCamel = Str::camel($this->modelNamePlural);
68 | $this->initDynamicVariables();
69 | }
70 |
71 | public function getInputFields()
72 | {
73 | $fields = [];
74 |
75 | $this->commandObj->info('Specify fields for the model (skip id & timestamp fields, will be added automatically)');
76 | $this->commandObj->info('Enter exit to finish');
77 |
78 | while (true) {
79 | $fieldInputStr = $this->commandObj->ask('Field: (field_name:field_database_type)', '');
80 |
81 | if (empty($fieldInputStr) || $fieldInputStr == false || $fieldInputStr == 'exit') {
82 | break;
83 | }
84 |
85 | if (!GeneratorUtils::validateFieldInput($fieldInputStr)) {
86 | $this->commandObj->error('Invalid Input. Try again');
87 | continue;
88 | }
89 |
90 | $type = $this->commandObj->ask('Enter field html input type (text): ', 'text');
91 |
92 | $validations = $this->commandObj->ask('Enter validations: ', false);
93 |
94 | $validations = ($validations == false) ? '' : $validations;
95 |
96 | $fields[] = GeneratorUtils::processFieldInput($fieldInputStr, $type, $validations);
97 | }
98 |
99 | return $fields;
100 | }
101 |
102 | public function initDynamicVariables()
103 | {
104 | $this->dynamicVars = self::getConfigDynamicVariables();
105 |
106 | $this->dynamicVars = array_merge($this->dynamicVars, [
107 | '$MODEL_NAME$' => $this->modelName,
108 |
109 | '$MODEL_NAME_CAMEL$' => $this->modelNameCamel,
110 |
111 | '$MODEL_NAME_PLURAL$' => $this->modelNamePlural,
112 |
113 | '$MODEL_NAME_PLURAL_CAMEL$' => $this->modelNamePluralCamel,
114 | ]);
115 |
116 | if ($this->tableName) {
117 | $this->dynamicVars['$TABLE_NAME$'] = $this->tableName;
118 | } else {
119 | $this->dynamicVars['$TABLE_NAME$'] = $this->modelNamePluralCamel;
120 | }
121 | }
122 |
123 | public function addDynamicVariable($name, $val)
124 | {
125 | $this->dynamicVars[$name] = $val;
126 | }
127 |
128 | public static function getConfigDynamicVariables()
129 | {
130 | return [
131 |
132 | '$BASE_CONTROLLER$' => Config::get('generator.base_controller', 'Mitul\Controller\AppBaseController'),
133 |
134 | '$NAMESPACE_CONTROLLER$' => Config::get('generator.namespace_controller', 'App\Http\Controllers'),
135 |
136 | '$NAMESPACE_API_CONTROLLER$' => Config::get('generator.namespace_api_controller', 'App\Http\Controllers\API'),
137 |
138 | '$NAMESPACE_REQUEST$' => Config::get('generator.namespace_request', 'App\Http\Requests'),
139 |
140 | '$NAMESPACE_REPOSITORY$' => Config::get('generator.namespace_repository', 'App\Libraries\Repositories'),
141 |
142 | '$NAMESPACE_MODEL$' => Config::get('generator.namespace_model', 'App\Models'),
143 |
144 | '$NAMESPACE_MODEL_EXTEND$' => Config::get('generator.model_extend_class', 'Illuminate\Database\Eloquent\Model'),
145 |
146 | '$SOFT_DELETE_DATES$' => "\n\tprotected \$dates = ['deleted_at'];\n",
147 |
148 | '$SOFT_DELETE$' => "use SoftDeletes;\n",
149 |
150 | '$SOFT_DELETE_IMPORT$' => "use Illuminate\\Database\\Eloquent\\SoftDeletes;\n",
151 |
152 | '$API_PREFIX$' => Config::get('generator.api_prefix', 'api'),
153 |
154 | '$API_VERSION$' => Config::get('generator.api_version', 'v1'),
155 |
156 | '$PRIMARY_KEY$' => 'id',
157 | ];
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/Commands/APIGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | commandData = new CommandData($this, CommandData::$COMMAND_TYPE_API);
36 | }
37 |
38 | /**
39 | * Execute the command.
40 | *
41 | * @return void
42 | */
43 | public function handle()
44 | {
45 | parent::handle();
46 |
47 | if (!$this->commandData->skipMigration) {
48 | $migrationGenerator = new MigrationGenerator($this->commandData);
49 | $migrationGenerator->generate();
50 | }
51 |
52 | $modelGenerator = new ModelGenerator($this->commandData);
53 | $modelGenerator->generate();
54 |
55 | $repositoryGenerator = new RepositoryGenerator($this->commandData);
56 | $repositoryGenerator->generate();
57 |
58 | $repoControllerGenerator = new APIControllerGenerator($this->commandData);
59 | $repoControllerGenerator->generate();
60 |
61 | $routeGenerator = new RoutesGenerator($this->commandData);
62 | $routeGenerator->generate();
63 |
64 | if ($this->confirm("\nDo you want to migrate database? [y|N]", false)) {
65 | $this->call('migrate');
66 | }
67 | }
68 |
69 | /**
70 | * Get the console command arguments.
71 | *
72 | * @return array
73 | */
74 | protected function getArguments()
75 | {
76 | return array_merge(parent::getArguments(), []);
77 | }
78 |
79 | /**
80 | * Get the console command options.
81 | *
82 | * @return array
83 | */
84 | public function getOptions()
85 | {
86 | return array_merge(parent::getOptions(), []);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/Commands/BaseCommand.php:
--------------------------------------------------------------------------------
1 | commandData->modelName = $this->argument('model');
26 | $this->commandData->useSoftDelete = $this->option('softDelete');
27 | $this->commandData->fieldsFile = $this->option('fieldsFile');
28 | $this->commandData->paginate = $this->option('paginate');
29 | $this->commandData->tableName = $this->option('tableName');
30 | $this->commandData->skipMigration = $this->option('skipMigration');
31 | $this->commandData->fromTable = $this->option('fromTable');
32 | $this->commandData->rememberToken = $this->option('rememberToken');
33 |
34 | if ($this->commandData->fromTable) {
35 | if (!$this->commandData->tableName) {
36 | $this->error('tableName required with fromTable option.');
37 | exit;
38 | }
39 | }
40 |
41 | if ($this->commandData->paginate <= 0) {
42 | $this->commandData->paginate = 10;
43 | }
44 |
45 | $this->commandData->initVariables();
46 | $this->commandData->addDynamicVariable('$NAMESPACE_APP$', $this->getLaravel()->getNamespace());
47 |
48 | if ($this->commandData->fieldsFile) {
49 | $fileHelper = new FileHelper();
50 | try {
51 | if (file_exists($this->commandData->fieldsFile)) {
52 | $filePath = $this->commandData->fieldsFile;
53 | } else {
54 | $filePath = base_path($this->commandData->fieldsFile);
55 | }
56 |
57 | if (!file_exists($filePath)) {
58 | $this->commandData->commandObj->error('Fields file not found');
59 | exit;
60 | }
61 |
62 | $fileContents = $fileHelper->getFileContents($filePath);
63 | $fields = json_decode($fileContents, true);
64 |
65 | $this->commandData->inputFields = GeneratorUtils::validateFieldsFile($fields);
66 | } catch (Exception $e) {
67 | $this->commandData->commandObj->error($e->getMessage());
68 | exit;
69 | }
70 | } elseif ($this->commandData->fromTable) {
71 | $tableFieldsGenerator = new TableFieldsGenerator($this->commandData->tableName);
72 | $this->commandData->inputFields = $tableFieldsGenerator->generateFieldsFromTable();
73 | } else {
74 | $this->commandData->inputFields = $this->commandData->getInputFields();
75 | }
76 | }
77 |
78 | /**
79 | * Get the console command arguments.
80 | *
81 | * @return array
82 | */
83 | protected function getArguments()
84 | {
85 | return [
86 | ['model', InputArgument::REQUIRED, 'Singular Model name'],
87 | ];
88 | }
89 |
90 | /**
91 | * Get the console command options.
92 | *
93 | * @return array
94 | */
95 | public function getOptions()
96 | {
97 | return [
98 | ['softDelete', null, InputOption::VALUE_NONE, 'Use Soft Delete trait'],
99 | ['fieldsFile', null, InputOption::VALUE_REQUIRED, 'Fields input as json file'],
100 | ['paginate', null, InputOption::VALUE_OPTIONAL, 'Pagination for index.blade.php', 10],
101 | ['tableName', null, InputOption::VALUE_REQUIRED, 'Table Name'],
102 | ['skipMigration', null, InputOption::VALUE_NONE, 'Skip Migration generation'],
103 | ['fromTable', null, InputOption::VALUE_NONE, 'Generate from table'],
104 | ['rememberToken', null, InputOption::VALUE_NONE, 'Generate rememberToken field in migration'],
105 | ];
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/Commands/PublisherCommand.php:
--------------------------------------------------------------------------------
1 | option('all')) {
38 | $this->publishCommonViews();
39 | $this->publishAPIRoutes();
40 | $this->initAPIRoutes();
41 | $this->publishTemplates();
42 | $this->publishAppBaseController();
43 | } elseif ($this->option('templates')) {
44 | $this->publishTemplates();
45 | } elseif ($this->option('baseController')) {
46 | $this->publishAppBaseController();
47 | } else {
48 | $this->publishCommonViews();
49 | $this->publishAPIRoutes();
50 | $this->initAPIRoutes();
51 | }
52 | }
53 |
54 | /**
55 | * Get the console command arguments.
56 | *
57 | * @return array
58 | */
59 | protected function getArguments()
60 | {
61 | return [];
62 | }
63 |
64 | /**
65 | * Get the console command options.
66 | *
67 | * @return array
68 | */
69 | public function getOptions()
70 | {
71 | return [
72 | ['templates', null, InputOption::VALUE_NONE, 'Publish templates'],
73 | ['baseController', null, InputOption::VALUE_NONE, 'Publish base controller'],
74 | ['all', null, InputOption::VALUE_NONE, 'Publish all options'],
75 | ];
76 | }
77 |
78 | /**
79 | * Publishes templates.
80 | */
81 | public function publishTemplates()
82 | {
83 | $templatesPath = __DIR__.'/../../../../templates';
84 |
85 | $templatesCopyPath = base_path('resources/api-generator-templates');
86 |
87 | $this->publishDirectory($templatesPath, $templatesCopyPath, 'templates');
88 | }
89 |
90 | /**
91 | * Publishes common views.
92 | */
93 | public function publishCommonViews()
94 | {
95 | $viewsPath = __DIR__.'/../../../../views/common';
96 |
97 | $viewsCopyPath = base_path('resources/views/common');
98 |
99 | $this->publishDirectory($viewsPath, $viewsCopyPath, 'common views');
100 | }
101 |
102 | /**
103 | * Publishes base controller.
104 | */
105 | private function publishAppBaseController()
106 | {
107 | $templateHelper = new TemplatesHelper();
108 | $templateData = $templateHelper->getTemplate('AppBaseController', 'controller');
109 |
110 | $templateData = GeneratorUtils::fillTemplate(CommandData::getConfigDynamicVariables(), $templateData);
111 |
112 | $fileName = 'AppBaseController.php';
113 |
114 | $filePath = Config::get('generator.path_controller', app_path('Http/Controllers/'));
115 |
116 | $fileHelper = new FileHelper();
117 | $fileHelper->writeFile($filePath.$fileName, $templateData);
118 | $this->comment('AppBaseController generated');
119 | $this->info($fileName);
120 | }
121 |
122 | /**
123 | * Publishes api_routes.php.
124 | */
125 | public function publishAPIRoutes()
126 | {
127 | $routesPath = __DIR__.'/../../../../templates/routes/api_routes.stub';
128 |
129 | $apiRoutesPath = Config::get('generator.path_api_routes', app_path('Http/api_routes.php'));
130 |
131 | $this->publishFile($routesPath, $apiRoutesPath, 'api_routes.php');
132 | }
133 |
134 | public function publishFile($sourceFile, $destinationFile, $fileName)
135 | {
136 | if (file_exists($destinationFile)) {
137 | $answer = $this->ask('Do you want to overwrite '.$fileName.'? (y|N) :', false);
138 |
139 | if (strtolower($answer) != 'y' and strtolower($answer) != 'yes') {
140 | return;
141 | }
142 | }
143 |
144 | copy($sourceFile, $destinationFile);
145 |
146 | $this->comment($fileName.' generated');
147 | $this->info($destinationFile);
148 | }
149 |
150 | public function publishDirectory($sourceDir, $destinationDir, $dirName)
151 | {
152 | if (file_exists($destinationDir)) {
153 | $answer = $this->ask('Do you want to overwrite '.$dirName.'? (y|N) :', false);
154 |
155 | if (strtolower($answer) != 'y' and strtolower($answer) != 'yes') {
156 | return;
157 | }
158 | } else {
159 | File::makeDirectory($destinationDir);
160 | }
161 |
162 | File::copyDirectory($sourceDir, $destinationDir);
163 |
164 | $this->comment($dirName.' published');
165 | $this->info($destinationDir);
166 | }
167 |
168 | /**
169 | * Initialize routes group based on route integration.
170 | */
171 | private function initAPIRoutes()
172 | {
173 | $path = Config::get('generator.path_routes', app_path('Http/routes.php'));
174 |
175 | $fileHelper = new FileHelper();
176 | $routeContents = $fileHelper->getFileContents($path);
177 |
178 | $useDingo = Config::get('generator.use_dingo_api', false);
179 |
180 | if ($useDingo) {
181 | $template = 'dingo_api_routes_group';
182 | } else {
183 | $template = 'api_routes_group';
184 | }
185 |
186 | $templateHelper = new TemplatesHelper();
187 | $templateData = $templateHelper->getTemplate($template, 'routes');
188 |
189 | $templateData = $this->fillTemplate($templateData);
190 |
191 | $fileHelper->writeFile($path, $routeContents."\n\n".$templateData);
192 | $this->comment("\nAPI group added to routes.php");
193 | }
194 |
195 | /**
196 | * Replaces dynamic variables of template.
197 | *
198 | * @param string $templateData
199 | *
200 | * @return string
201 | */
202 | private function fillTemplate($templateData)
203 | {
204 | $apiVersion = Config::get('generator.api_version');
205 | $apiPrefix = Config::get('generator.api_prefix');
206 | $apiNamespace = Config::get('generator.namespace_api_controller');
207 |
208 | $templateData = str_replace('$API_VERSION$', $apiVersion, $templateData);
209 | $templateData = str_replace('$NAMESPACE_API_CONTROLLER$', $apiNamespace, $templateData);
210 | $templateData = str_replace('$API_PREFIX$', $apiPrefix, $templateData);
211 |
212 | return $templateData;
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/Commands/ScaffoldAPIGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | commandData = new CommandData($this, CommandData::$COMMAND_TYPE_SCAFFOLD_API);
37 | }
38 |
39 | /**
40 | * Execute the command.
41 | *
42 | * @return void
43 | */
44 | public function handle()
45 | {
46 | parent::handle();
47 |
48 | if (!$this->commandData->skipMigration) {
49 | $migrationGenerator = new MigrationGenerator($this->commandData);
50 | $migrationGenerator->generate();
51 | }
52 |
53 | $modelGenerator = new ModelGenerator($this->commandData);
54 | $modelGenerator->generate();
55 |
56 | $requestGenerator = new RequestGenerator($this->commandData);
57 | $requestGenerator->generate();
58 |
59 | $repositoryGenerator = new RepositoryGenerator($this->commandData);
60 | $repositoryGenerator->generate();
61 |
62 | $repoControllerGenerator = new APIControllerGenerator($this->commandData);
63 | $repoControllerGenerator->generate();
64 |
65 | $viewsGenerator = new ViewGenerator($this->commandData);
66 | $viewsGenerator->generate();
67 |
68 | $repoControllerGenerator = new ViewControllerGenerator($this->commandData);
69 | $repoControllerGenerator->generate();
70 |
71 | $routeGenerator = new RoutesGenerator($this->commandData);
72 | $routeGenerator->generate();
73 |
74 | if ($this->confirm("\nDo you want to migrate database? [y|N]", false)) {
75 | $this->call('migrate');
76 | }
77 | }
78 |
79 | /**
80 | * Get the console command arguments.
81 | *
82 | * @return array
83 | */
84 | protected function getArguments()
85 | {
86 | return array_merge(parent::getArguments(), []);
87 | }
88 |
89 | /**
90 | * Get the console command options.
91 | *
92 | * @return array
93 | */
94 | public function getOptions()
95 | {
96 | return array_merge(parent::getOptions(), []);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/Commands/ScaffoldGeneratorCommand.php:
--------------------------------------------------------------------------------
1 | commandData = new CommandData($this, CommandData::$COMMAND_TYPE_SCAFFOLD);
38 | }
39 |
40 | /**
41 | * Execute the command.
42 | *
43 | * @return void
44 | */
45 | public function handle()
46 | {
47 | parent::handle();
48 |
49 | if (!$this->commandData->skipMigration and !$this->commandData->fromTable) {
50 | $migrationGenerator = new MigrationGenerator($this->commandData);
51 | $migrationGenerator->generate();
52 | }
53 |
54 | $modelGenerator = new ModelGenerator($this->commandData);
55 | $modelGenerator->generate();
56 |
57 | $requestGenerator = new RequestGenerator($this->commandData);
58 | $requestGenerator->generate();
59 |
60 | $repositoryGenerator = new RepositoryGenerator($this->commandData);
61 | $repositoryGenerator->generate();
62 |
63 | $repoControllerGenerator = new ViewControllerGenerator($this->commandData);
64 | $repoControllerGenerator->generate();
65 |
66 | $viewsGenerator = new ViewGenerator($this->commandData);
67 | $viewsGenerator->generate();
68 |
69 | $routeGenerator = new RoutesGenerator($this->commandData);
70 | $routeGenerator->generate();
71 |
72 | if ($this->confirm("\nDo you want to migrate database? [y|N]", false)) {
73 | $this->call('migrate');
74 | }
75 | }
76 |
77 | /**
78 | * Get the console command arguments.
79 | *
80 | * @return array
81 | */
82 | protected function getArguments()
83 | {
84 | return array_merge(parent::getArguments());
85 | }
86 |
87 | /**
88 | * Get the console command options.
89 | *
90 | * @return array
91 | */
92 | public function getOptions()
93 | {
94 | return array_merge(parent::getOptions(), []);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/Errors.php:
--------------------------------------------------------------------------------
1 | [
20 | 'message' => 'Somewhere something happened and someone already working to fix that!',
21 | 'system_message' => 'Unknown error',
22 | 'error_code' => self::UNKNOWN_ERROR,
23 | 'exception' => 'ServiceUnavailableHttpException',
24 | ],
25 |
26 | self::VALIDATION_ERROR => [
27 | 'message' => 'Oops, some fields looks like incorrect!',
28 | 'system_message' => 'Validation error',
29 | 'error_code' => self::VALIDATION_ERROR,
30 | 'exception' => 'BadRequestHttpException',
31 | ],
32 |
33 | self::NOT_FOUND => [
34 | 'message' => 'Sorry, we could not find requested resource',
35 | 'system_message' => 'Record not found',
36 | 'error_code' => self::NOT_FOUND,
37 | 'exception' => 'NotFoundHttpException',
38 | ],
39 |
40 | self::CREATION_FORM_NOT_EXISTS => [
41 | 'message' => 'Sorry, we have nothing on this address',
42 | 'system_message' => 'Form of creating is not supported in API',
43 | 'error_code' => self::CREATION_FORM_NOT_EXISTS,
44 | 'exception' => 'NotFoundHttpException',
45 | ],
46 |
47 | self::EDITION_FORM_NOT_EXISTS => [
48 | 'message' => 'Sorry, we have nothing on this address',
49 | 'system_message' => 'Form of editing is not supported in API',
50 | 'error_code' => self::EDITION_FORM_NOT_EXISTS,
51 | 'exception' => 'NotFoundHttpException',
52 | ],
53 | ];
54 |
55 | /**
56 | * Get (with help links) errors with some codes / get unknown error or all errors.
57 | *
58 | * @param array $codes filter errors by single code or array of codes
59 | * @param array $payload error description [error code => useful info]
60 | * @param bool $get_all return all errors, if code not specified
61 | *
62 | * @return array
63 | */
64 | public static function getErrors($codes = [], array $payload = [], $get_all = false)
65 | {
66 | $codes = (array) $codes;
67 | if (empty($codes) && $get_all) {
68 | $codes = array_keys(static::$errors);
69 | }
70 | $return = [];
71 | foreach ($codes as $code) {
72 | if (isset(static::$errors[$code])) {
73 | $return[$code] = static::$errors[$code];
74 | unset($return[$code]['exception']);
75 | $return[$code]['help'] = '/errors/'.$code;
76 | $return[$code]['payload'] = isset($payload[$code])
77 | ? $payload[$code]
78 | : [];
79 | }
80 | }
81 | if (empty($return)) {
82 | if (!empty($codes)) {
83 | $payload = [self::UNKNOWN_ERROR => 'Unknown error codes: '.implode(',', $codes)];
84 | }
85 | $return = static::getErrors([self::UNKNOWN_ERROR], $payload);
86 | }
87 |
88 | return $return;
89 | }
90 |
91 | /**
92 | * throw HttpException error, that is not registered in Errors::$errors array and mix data inside.
93 | *
94 | * @param Exception\HttpException $exception
95 | * @param $help_link
96 | * @param string $system_message
97 | * @param array $payload
98 | * @param array $hateoas Send here static::getHATEOAS(['%id' => $id, '%placeholder' => 'value']) from generated controller
99 | * @param array $replacements additional info inside response
100 | */
101 | public static function throwHttpException(Exception\HttpException $exception, $help_link, $system_message = '', $payload = [], $hateoas = [], $replacements = [])
102 | {
103 | $replacements = self::getReplacements($system_message, $payload, $help_link, $replacements);
104 | app('api.exception')->setReplacements($replacements);
105 | throw $exception;
106 | }
107 |
108 | /**
109 | * Throw HttpException with specified or unknown error.
110 | *
111 | * @param mixed $error_code send exception for error with code
112 | * @param [] $payload error description [error code => useful info]
113 | * @param array $hateoas Send here static::getHATEOAS(['%id' => $id, '%placeholder' => 'value']) from generated controller
114 | * @param array $replacements additional info inside response
115 | */
116 | public static function throwHttpExceptionWithCode($error_code = null, $payload = [], $hateoas = [], $replacements = [])
117 | {
118 | $errors = static::getErrors([$error_code], [$error_code => $payload]);
119 | $error = current($errors);
120 | $replacements = self::getReplacements($error['system_message'], $error['payload'], $error['help'], $hateoas, $replacements);
121 | app('api.exception')->setReplacements($replacements);
122 | $exception = self::getExceptionObject(static::$errors[$error['error_code']]['exception'], $error);
123 | throw $exception;
124 | }
125 |
126 | /**
127 | * @param string $exception_class
128 | * @param array $error item from self::$errors
129 | *
130 | * @return mixed
131 | *
132 | * @internal param $exception
133 | */
134 | protected static function getExceptionObject($exception_class, $error)
135 | {
136 | $exception = static::$exception_namespace.$exception_class;
137 | switch ($exception_class) {
138 | case 'MethodNotAllowedHttpException':
139 | return new $exception([], $error['message'], null, [], $error['error_code']);
140 | case 'HttpException':
141 | return new $exception(400, $error['message'], null, [], $error['error_code']);
142 | case 'ServiceUnavailableHttpException':
143 | case 'TooManyRequestsHttpException':
144 | return new $exception(3600, $error['message'], null, $error['error_code']);
145 | case 'UnauthorizedHttpException':
146 | return new $exception('', $error['message'], null, $error['error_code']);
147 | default:
148 | return new $exception($error['message'], null, $error['error_code']);
149 | }
150 | }
151 |
152 | /**
153 | * Get array of replacements for mixing to Exception.
154 | *
155 | *
156 | * setReplacements(Errors::getReplacements('Not found', ['id' => 1111], 'help/article_not_found'));
158 | * throw new HttpException(404, 'Sorry, article is not found');
159 | * ?>
160 | *
161 | *
162 | * @param $system_message
163 | * @param $payload
164 | * @param $help_link
165 | * @param array $hateoas Send here static::getHATEOAS(['%id' => $id, '%placeholder' => 'value']) from generated controller
166 | * @param array $replacements
167 | *
168 | * @return array
169 | */
170 | public static function getReplacements($system_message = '', $payload = [], $help_link = '', $hateoas = [], $replacements = [])
171 | {
172 | if ($system_message) {
173 | $replacements[':system_message'] = $system_message;
174 | }
175 | if (!empty($payload)) {
176 | $replacements[':payload'] = $payload;
177 | }
178 | if ($help_link) {
179 | $replacements[':help'] = $help_link;
180 | }
181 | if (!empty($hateoas)) {
182 | $replacements[':links'] = $hateoas;
183 | }
184 |
185 | return $replacements;
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/src/Mitul/Generator/File/FileHelper.php:
--------------------------------------------------------------------------------
1 | 'form-control-label $FIELD_NAME_TITLE$']) !!}";
14 | $template = str_replace('$FIELD_NAME_TITLE$', $label, $template);
15 | $template = str_replace('$FIELD_NAME$', $field['fieldName'], $template);
16 | return $template;
17 | }
18 |
19 | private static function replaceFieldVars($textField, $field)
20 | {
21 | $label = Str::title(str_replace('_', ' ', $field['fieldName']));
22 |
23 | $textField = str_replace('$FIELD_NAME$', $field['fieldName'], $textField);
24 | $textField = str_replace('$FIELD_NAME_TITLE$', $label, $textField);
25 | $textField = str_replace('$FIELD_INPUT$', $textField, $textField);
26 |
27 | return $textField;
28 | }
29 |
30 | public static function text($templateData, $field)
31 | {
32 | $textField = self::generateLabel($field);
33 |
34 | $textField .= "\n\t{!! Form::text('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}";
35 |
36 | $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData);
37 |
38 | $templateData = self::replaceFieldVars($templateData, $field);
39 |
40 | return $templateData;
41 | }
42 |
43 | public static function textarea($templateData, $field)
44 | {
45 | $textareaField = self::generateLabel($field);
46 |
47 | $textareaField .= "\n\t{!! Form::textarea('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}";
48 |
49 | $templateData = str_replace('$FIELD_INPUT$', $textareaField, $templateData);
50 |
51 | $templateData = self::replaceFieldVars($templateData, $field);
52 |
53 | return $templateData;
54 | }
55 |
56 | public static function password($templateData, $field)
57 | {
58 | $textField = self::generateLabel($field);
59 |
60 | $textField .= "\n\t{!! Form::password('\$FIELD_NAME\$', ['class' => 'form-control']) !!}";
61 |
62 | $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData);
63 |
64 | $templateData = self::replaceFieldVars($templateData, $field);
65 |
66 | return $templateData;
67 | }
68 |
69 | public static function email($templateData, $field)
70 | {
71 | $textField = self::generateLabel($field);
72 |
73 | $textField .= "\n\t{!! Form::email('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}";
74 | $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData);
75 |
76 | $templateData = self::replaceFieldVars($templateData, $field);
77 |
78 | return $templateData;
79 | }
80 |
81 | public static function file($templateData, $field)
82 | {
83 | $textField = self::generateLabel($field);
84 |
85 | $textField .= "\n\t{!! Form::file('\$FIELD_NAME\$') !!}";
86 |
87 | $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData);
88 |
89 | $templateData = self::replaceFieldVars($templateData, $field);
90 |
91 | return $templateData;
92 | }
93 |
94 | public static function checkbox($templateData, $field)
95 | {
96 | $textField = "
{!! $$MODEL_NAME_CAMEL$->$FIELD_NAME$ !!}
5 |Action | 5 | 6 | 7 | @foreach($$MODEL_NAME_PLURAL_CAMEL$ as $$MODEL_NAME_CAMEL$) 8 |
---|
11 | 12 | 13 | | 14 |