Skip to content

Commit d10acd7

Browse files
committed
=Fixes couple bugs with the views command
1 parent 4c66e6b commit d10acd7

27 files changed

+216
-172
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# An awesome code generator for laravel framework - with client-side validation
22

3-
For full documentation and screenshots please visit <a href="https://crestapps.com/laravel-code-generator/docs/1.1" target="_blank" title="Laravel Code Generator Documentation">CrestApps.com</a>
4-
3+
For full documentation and live demo please visit <a href="https://crestapps.com/laravel-code-generator/docs/1.1" target="_blank" title="Laravel Code Generator Documentation">CrestApps.com</a>
54

65
## Introduction
76

@@ -26,10 +25,8 @@ A clean code generator for Laravel framework that will save you time! This aweso
2625
* Ability to generate views with and without Laravel-Collective.
2726
* Lots of documentation.
2827

29-
3028
## Installation
3129

32-
3330
To download this package into your laravel project, use the command-line to execute the following command
3431
```
3532
composer require crestapps/laravel-code-generator --dev
@@ -71,7 +68,9 @@ php artisan vendor:publish --provider="CrestApps\CodeGenerator\CodeGeneratorServ
7168
* php artisan create:language [language-file-name]
7269
* php artisan create:fields-file [table-name]
7370

74-
> Full documentation available at [CrestApps.com](https://crestapps.com/laravel-code-generator/docs/1.1 "Laravel Code Generator Documentation").
71+
> Full documentation available at [CrestApps.com](https://www.crestapps.com/laravel-code-generator/docs/1.1 "Laravel Code Generator Documentation").
72+
73+
> Live demo is available at [CrestApps.com](https://www.crestapps.com/laravel-code-generator/demos/1.1 "Laravel Code Generator Live Demo").
7574
7675

7776
## License

src/Commands/CreateControllerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function isContainMultipleAnswers(array $fields)
139139
/**
140140
* Calls the create:form-request command
141141
*
142-
* @param CrestApps\CodeGenerator\Support\ViewInput $input
142+
* @param CrestApps\CodeGenerator\Models\ViewInput $input
143143
*
144144
* @return $this
145145
*/

src/Commands/CreateCreateViewCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ protected function handleCreateView()
5252
$fields = $this->getFields($input->fields, $input->languageFileName, $input->fieldsFile);
5353
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'create');
5454

55-
$this->handleNewFilePolicy($destenationFile, $input->force)
56-
->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
57-
->createMissingViews($input)
58-
->replaceCommonTemplates($stub, $input)
59-
->replaceFileUpload($stub, $fields)
60-
->createViewFile($stub, $destenationFile)
61-
->info('A "create view" was created successfully.');
55+
if($this->canCreateView($destenationFile, $input->force))
56+
{
57+
$this->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
58+
->createMissingViews($input)
59+
->replaceCommonTemplates($stub, $input)
60+
->replaceFileUpload($stub, $fields)
61+
->createViewFile($stub, $destenationFile)
62+
->info('Create view was crafted successfully.');
63+
}
6264

6365
}
6466

src/Commands/CreateEditViewCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ protected function handleCreateView()
5252
$fields = $this->getFields($input->fields, $input->languageFileName, $input->fieldsFile);
5353
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'edit');
5454

55-
$this->handleNewFilePolicy($destenationFile, $input->force, $fields)
56-
->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
57-
->createMissingViews($input)
58-
->replaceCommonTemplates($stub, $input)
59-
->replaceFileUpload($stub, $fields)
60-
->replacePrimaryKey($stub, $this->getPrimaryKeyName($fields))
61-
->createViewFile($stub, $destenationFile)
62-
->info('An "edit-view" view was created successfully.');
55+
if($this->canCreateView($destenationFile, $input->force, $fields))
56+
{
57+
$this->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
58+
->createMissingViews($input)
59+
->replaceCommonTemplates($stub, $input)
60+
->replaceFileUpload($stub, $fields)
61+
->replacePrimaryKey($stub, $this->getPrimaryKeyName($fields))
62+
->createViewFile($stub, $destenationFile)
63+
->info('Edit view view was crafted successfully.');
64+
}
6365
}
6466

6567

src/Commands/CreateFieldsFileCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace CrestApps\CodeGenerator\Commands;
44

55
use Illuminate\Console\Command;
6-
use CrestApps\CodeGenerator\Support\Field;
6+
use CrestApps\CodeGenerator\Models\Field;
77
use CrestApps\CodeGenerator\Support\Helpers;
88
use CrestApps\CodeGenerator\traits\CommonCommand;
99
use DB;

src/Commands/CreateFormViewCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ protected function handleCreateView()
5555
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'form');
5656
$htmlCreator = $this->getHtmlGenerator($fields, $input->modelName ,$this->getTemplateName());
5757

58-
$this->handleNewFilePolicy($destenationFile, $input->force)
59-
->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
60-
->replaceCommonTemplates($stub, $input)
61-
->replaceFields($stub, $htmlCreator->getHtmlFields())
62-
->createViewFile($stub, $destenationFile)
63-
->info('Form view was created successfully.');
58+
if($this->canCreateView($destenationFile, $input->force))
59+
{
60+
$this->createLanguageFile($input->languageFileName, $input->fields, $input->fieldsFile)
61+
->replaceCommonTemplates($stub, $input)
62+
->replaceFields($stub, $htmlCreator->getHtmlFields())
63+
->createViewFile($stub, $destenationFile)
64+
->info('Form view was crafted successfully.');
65+
}
6466
}
6567

6668
/**

src/Commands/CreateIndexViewCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ protected function handleCreateView()
5555
$destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix, 'index');
5656
$htmlCreator = $this->getHtmlGenerator($fields, $input->modelName ,$this->getTemplateName());
5757

58-
$this->handleNewFilePolicy($destenationFile, $input->force, $fields)
59-
->replaceCommonTemplates($stub, $input)
60-
->replacePrimaryKey($stub, $this->getPrimaryKeyName($fields))
61-
->replaceHeaderCells($stub, $htmlCreator->getIndexHeaderCells())
62-
->replaceBodyCells($stub, $htmlCreator->getIndexBodyCells())
63-
->createViewFile($stub, $destenationFile)
64-
->info('Index view was created successfully.');
58+
if($this->canCreateView($destenationFile, $input->force, $fields))
59+
{
60+
$this->replaceCommonTemplates($stub, $input)
61+
->replacePrimaryKey($stub, $this->getPrimaryKeyName($fields))
62+
->replaceHeaderCells($stub, $htmlCreator->getIndexHeaderCells())
63+
->replaceBodyCells($stub, $htmlCreator->getIndexBodyCells())
64+
->createViewFile($stub, $destenationFile)
65+
->info('Index view was crafted successfully.');
66+
}
6567
}
6668

6769
/**

src/Commands/CreateLanguageCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Console\Command;
77
use CrestApps\CodeGenerator\Support\Helpers;
88
use CrestApps\CodeGenerator\Traits\CommonCommand;
9-
use CrestApps\CodeGenerator\Support\Label;
9+
use CrestApps\CodeGenerator\Models\Label;
1010
use CrestApps\CodeGenerator\Support\CrestAppsTranslator;
1111

1212
class CreateLanguageCommand extends Command

src/Commands/CreateMigrationCommand.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Exception;
77
use Illuminate\Console\Command;
88
use CrestApps\CodeGenerator\Support\Helpers;
9-
use CrestApps\CodeGenerator\Support\Field;
9+
use CrestApps\CodeGenerator\Models\Field;
1010
use CrestApps\CodeGenerator\Traits\CommonCommand;
1111

1212
class CreateMigrationCommand extends Command
@@ -395,7 +395,7 @@ protected function addFieldPropertyClousure(& $property)
395395
* Adds a 'field type' to the property
396396
*
397397
* @param string $property
398-
* @param CrestApps\CodeGenerator\Support\Field $field
398+
* @param CrestApps\CodeGenerator\Models\Field $field
399399
*
400400
* @return $this
401401
*/
@@ -425,7 +425,7 @@ protected function getTypeToMethodMap()
425425
/**
426426
* Constructs the second parameter to the type method
427427
*
428-
* @param CrestApps\CodeGenerator\Support\Field $field
428+
* @param CrestApps\CodeGenerator\Models\Field $field
429429
*
430430
* @return string
431431
*/
@@ -444,7 +444,7 @@ protected function getMethodParamerters(Field $field)
444444
/**
445445
* Constructs the second parameter to the enum type method
446446
*
447-
* @param CrestApps\CodeGenerator\Support\Field $field
447+
* @param CrestApps\CodeGenerator\Models\Field $field
448448
*
449449
* @return string
450450
*/
@@ -596,7 +596,7 @@ protected function replaceConnectionName(&$stub, $name)
596596
* Adds the field's "default" value to the giving property.
597597
*
598598
* @param string $property
599-
* @param CrestApps\CodeGenerator\Support\Field $field
599+
* @param CrestApps\CodeGenerator\Models\Field $field
600600
*
601601
* @return $this
602602
*/
@@ -614,7 +614,7 @@ protected function addFieldDefaultValue(& $property, Field $field)
614614
* Adds the field's "unsigned" value to the giving property.
615615
*
616616
* @param string $property
617-
* @param CrestApps\CodeGenerator\Support\Field $field
617+
* @param CrestApps\CodeGenerator\Models\Field $field
618618
*
619619
* @return $this
620620
*/
@@ -632,7 +632,7 @@ protected function addFieldUnsigned(& $property, Field $field)
632632
* Adds the field's "unique" value to the giving property.
633633
*
634634
* @param string $property
635-
* @param CrestApps\CodeGenerator\Support\Field $field
635+
* @param CrestApps\CodeGenerator\Models\Field $field
636636
*
637637
* @return $this
638638
*/
@@ -650,7 +650,7 @@ protected function addFieldUnique(& $property, Field $field)
650650
* Adds the field's "index" value to the giving property.
651651
*
652652
* @param string $property
653-
* @param CrestApps\CodeGenerator\Support\Field $field
653+
* @param CrestApps\CodeGenerator\Models\Field $field
654654
*
655655
* @return $this
656656
*/
@@ -668,7 +668,7 @@ protected function addFieldIndex(& $property, Field $field)
668668
* Adds the field's "nullable" value to the giving property.
669669
*
670670
* @param string $property
671-
* @param CrestApps\CodeGenerator\Support\Field $field
671+
* @param CrestApps\CodeGenerator\Models\Field $field
672672
*
673673
* @return $this
674674
*/
@@ -686,7 +686,7 @@ protected function addFieldNullable(& $property, Field $field)
686686
* Adds the field's "comment" value to the giving property.
687687
*
688688
* @param string $property
689-
* @param CrestApps\CodeGenerator\Support\Field $field
689+
* @param CrestApps\CodeGenerator\Models\Field $field
690690
*
691691
* @return $this
692692
*/
@@ -723,7 +723,7 @@ protected function addEngineName(& $property, $name)
723723
* Adds the table's "primary column" to the giving property.
724724
*
725725
* @param string $property
726-
* @param CrestApps\CodeGenerator\Support\Field $field
726+
* @param CrestApps\CodeGenerator\Models\Field $field
727727
*
728728
* @return $this
729729
*/
@@ -823,7 +823,7 @@ protected function makeFileName($name)
823823
{
824824
$filename = sprintf('%s_create_%s_table.php', date('Y_m_d_His'), strtolower($name));
825825

826-
return Helpers::postFixWith($name, '.php');
826+
return Helpers::postFixWith($filename, '.php');
827827
}
828828

829829

@@ -887,15 +887,16 @@ protected function makeFile($fileFullname, $stub, $force = false)
887887
{
888888
if(File::exists($fileFullname) && !$force)
889889
{
890-
throw new Exception('There is a migration exists with the same name! To override existing file try passing "--force" command');
890+
$this->error('The provided migration\'s name already exists!');
891+
return $this;
891892
}
892893

893894
if( ! File::put($fileFullname, $stub))
894895
{
895896
throw new Exception('The migration failed to create');
896897
}
897898

898-
$this->info('New migrations have been created');
899+
$this->info('Migrations have been created');
899900

900901
return $this;
901902
}

src/Commands/CreateModelCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Console\GeneratorCommand;
66
use CrestApps\CodeGenerator\Traits\CommonCommand;
77
use CrestApps\CodeGenerator\Support\Helpers;
8-
use CrestApps\CodeGenerator\Support\Field;
8+
use CrestApps\CodeGenerator\Models\Field;
99

1010
class CreateModelCommand extends GeneratorCommand
1111
{
@@ -284,7 +284,7 @@ protected function getMutators(array $fields = null)
284284
/**
285285
* Gets accessor for a giving field.
286286
*
287-
* @param CrestApps\CodeGenerator\Support\Field $field
287+
* @param CrestApps\CodeGenerator\Models\Field $field
288288
*
289289
* @return string
290290
*/
@@ -301,7 +301,7 @@ protected function getAccessor(Field $field)
301301
/**
302302
* Gets mutator for a giving field.
303303
*
304-
* @param CrestApps\CodeGenerator\Support\Field $field
304+
* @param CrestApps\CodeGenerator\Models\Field $field
305305
*
306306
* @return string
307307
*/

0 commit comments

Comments
 (0)