Skip to content

Commit 318e0fe

Browse files
author
Mike Alhayek
committed
Fixes a bug when using relations in the form view
1 parent 991b2b2 commit 318e0fe

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "crestapps/laravel-code-generator",
33
"license": "MIT",
44
"description": "A clean code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages or request-forms! It is extremely flexible and customizable to cover many use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.",
5-
"version": "v2.1.1",
5+
"version": "v2.1.2",
66
"keywords": [
77
"laravel","crud","crud generator",
88
"laravel crud generator","laravel crud builder",

config/codegenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
]
272272
],
273273
[
274-
'match' => ['*_date'],
274+
'match' => ['*_date','date_*'],
275275
'set' => [
276276
'data-type' => 'date',
277277
'date-format' => 'm/d/Y',

src/CodeGeneratorServiceProvider.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66

77
class CodeGeneratorServiceProvider extends ServiceProvider
88
{
9-
/**
10-
* Indicates if loading of the provider is deferred.
11-
*
12-
* @var bool
13-
*/
14-
protected $defer = false;
15-
169
/**
1710
* Perform post-registration booting of services.
1811
*
1912
* @return void
2013
*/
2114
public function boot()
2215
{
23-
$this->publishes([
24-
__DIR__ . '/../config/codegenerator.php' => config_path('codegenerator.php'),
25-
], 'default');
16+
$dir = __DIR__ . '/../';
2617

2718
$this->publishes([
28-
__DIR__ . '/../templates/default' => base_path('resources/codegenerator-templates/default'),
19+
$dir . 'config/codegenerator.php' => config_path('codegenerator.php'),
20+
$dir . 'templates/default' => base_path('resources/codegenerator-templates/default'),
2921
], 'default');
3022

3123
$this->publishes([
32-
__DIR__ . '/../templates/default-collective' => base_path('resources/codegenerator-templates/default-collective'),
24+
$dir . 'templates/default-collective' => base_path('resources/codegenerator-templates/default-collective'),
3325
], 'default-collective');
3426

3527
$this->createDirectory(base_path('resources/codegenerator-files'));

src/HtmlGenerators/HtmlGeneratorBase.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ protected function getPickItemsHtmlField(Field $field, Label $option, Validation
412412
$filename = sprintf('form-pickitems%s-field.blade', $field->isInlineOptions ? '-inline' : '');
413413
$stub = $this->getStubContent($filename, $this->template);
414414
$fieldName = ($field->isMultipleAnswers) ? $this->getFieldNameAsArray($field->name) : $field->name;
415-
415+
$checkedItem = $this->getCheckedItemForPickItem($option->value, $field->name, $field->isMultipleAnswers, $field->htmlValue);
416416
$this->replaceFieldType($stub, $field->htmlType)
417417
->replaceFieldName($stub, $fieldName)
418418
->replaceOptionValue($stub, $option->value)
419-
->replaceCheckedItem($stub, $this->getCheckedItemForPickItem($option->value, $field->name, $field->isMultipleAnswers, $field->htmlValue))
419+
->replaceCheckedItem($stub, $checkedItem)
420420
->replaceItemId($stub, $option->id)
421421
->replaceFieldRequired($stub, ($field->htmlType == 'checkbox') ? false : $parser->isRequired())
422422
->replaceCssClass($stub, $field->cssClass)
@@ -468,6 +468,13 @@ protected function getSelectHtmlField(Field $field, ValidationParser $parser)
468468
return $stub;
469469
}
470470

471+
/**
472+
* Gets the fields accessor
473+
*
474+
* @param CrestApps\CodeGeneraotor\Support\Field $field
475+
*
476+
* @return string
477+
*/
471478
protected function getFieldItem(Field $field)
472479
{
473480
if ($field->hasForeignRelation()) {
@@ -479,6 +486,13 @@ protected function getFieldItem(Field $field)
479486
return '$text';
480487
}
481488

489+
/**
490+
* Gets the fields item accessor
491+
*
492+
* @param CrestApps\CodeGeneraotor\Support\Field $field
493+
*
494+
* @return string
495+
*/
482496
protected function getFieldItemAccessor(Field $field)
483497
{
484498
if ($field->hasForeignRelation()) {
@@ -489,14 +503,15 @@ protected function getFieldItemAccessor(Field $field)
489503
return '$text';
490504
}
491505

506+
/**
507+
* Gets the field value accesor.
508+
*
509+
* @param CrestApps\CodeGeneraotor\Support\Field $field
510+
*
511+
* @return string
512+
*/
492513
protected function getFieldValueAccessor(Field $field)
493514
{
494-
if ($field->hasForeignRelation()) {
495-
$relation = $field->getForeignRelation();
496-
497-
return sprintf('$%s->%s', $relation->getSingleName(), $relation->getPrimaryKeyForForeignModel());
498-
}
499-
500515
return in_array($field->htmlType, ['selectRange','selectMonth']) ? '$value' : '$key';
501516
}
502517

0 commit comments

Comments
 (0)