Skip to content

Commit 35f453e

Browse files
committed
Fix the destenation location of the form request.
1 parent 0b91bdd commit 35f453e

29 files changed

+82
-48
lines changed

src/Commands/CreateControllerCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,13 @@ protected function getUseClassCommand($name)
428428
*/
429429
protected function getRelationAccessor(ForeignRelationship $collection)
430430
{
431-
return sprintf('$%s = %s::all();', $collection->getCollectionName(), $collection->getForeignModel());
431+
432+
return sprintf('$%s = %s::pluck(\'%s\',\'%s\')->all();',
433+
$collection->getCollectionName(),
434+
$collection->getForeignModel(),
435+
$collection->getField(),
436+
$collection->getPrimaryKeyForForeignModel()
437+
);
432438
}
433439

434440
/**

src/Commands/CreateFormRequestCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function handle()
4444

4545
$stub = $this->getStubContent('form-request', $input->template);
4646
$fields = $this->getFields($input->fields, 'crestapps', $input->fieldsFile);
47-
$destenationFile = Config::getRequestsPath() . $input->fileName . '.php';
47+
$destenationFile = $this->getDestenationFile($input->fileName);
4848
$validations = $this->getValidationRules($fields);
4949

5050
if ($this->alreadyExists($destenationFile)) {
@@ -60,6 +60,18 @@ public function handle()
6060
->info('A new form-request have been crafted!');
6161
}
6262

63+
/**
64+
* Gets the destenation's fullname
65+
*
66+
* @return string
67+
*/
68+
protected function getDestenationFile($name)
69+
{
70+
$path = base_path($this->getAppNamespace() . Config::getRequestsPath());
71+
72+
return Helpers::postFixWith($path, '/') . $name . '.php';
73+
}
74+
6375
/**
6476
* Gets a clean user inputs.
6577
*

src/HtmlGenerators/LaravelCollectiveHtml.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CrestApps\CodeGenerator\HtmlGenerators\HtmlGeneratorBase;
66
use CrestApps\CodeGenerator\Models\Label;
7+
use CrestApps\CodeGenerator\Models\Field;
78

89
class LaravelCollectiveHtml extends HtmlGeneratorBase
910
{
@@ -112,7 +113,7 @@ protected function getFieldMultiple($isMulti)
112113
*
113114
* @return string
114115
*/
115-
protected function getFieldItems(field $field)
116+
protected function getFieldItems(Field $field)
116117
{
117118
if ($field->hasForeignRelation() && $field->isOnFormView) {
118119
return sprintf('$%s', $field->getForeignRelation()->getCollectionName());

src/HtmlGenerators/StandardHtml.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected function getFieldMultiple($isMulti)
114114
*
115115
* @return string
116116
*/
117-
protected function getFieldItems(field $field)
117+
protected function getFieldItems(Field $field)
118118
{
119119
if ($field->hasForeignRelation() && $field->isOnFormView) {
120120
return sprintf('$%s', $field->getForeignRelation()->getCollectionName());
@@ -187,7 +187,7 @@ protected function getMultipleCheckedItem($value, $name)
187187
*/
188188
protected function getMultipleSelectedValue($name, $valueAccessor)
189189
{
190-
return sprintf(" {{ %s ? 'selected' : '' }}", $this->getMultipleRawOptionValue($name, $valueAccessor));
190+
return sprintf(" {{ %s ? 'selected' : '' }}", $name);
191191
}
192192

193193
/**
@@ -200,7 +200,7 @@ protected function getMultipleSelectedValue($name, $valueAccessor)
200200
*/
201201
protected function getSelectedValue($name, $valueAccessor)
202202
{
203-
return sprintf(" {{ %s == %s ? 'selected' : '' }}", $this->getRawOptionValue($name, ''), $valueAccessor);
203+
return sprintf(" {{ %s == %s ? 'selected' : '' }}", $this->getRawOptionValue($name, ''), '$key');
204204
}
205205

206206
/**

src/Support/FieldOptimizer.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function optimize()
7575
->optimizeBoolean()
7676
->optimizePrimaryKey()
7777
->optimizeValidations()
78-
->optimizeHtmlType();
78+
->optimizeHtmlType()
79+
->addPlaceHolder();
7980

8081
return $this;
8182
}
@@ -124,6 +125,20 @@ protected function optimizeDateFields()
124125
return $this;
125126
}
126127

128+
/**
129+
* If the field has a relation and the placeholder is missing, add generic one.
130+
*
131+
* @return $this
132+
*/
133+
protected function addPlaceHolder()
134+
{
135+
if(empty($this->field->placeHolder) && $this->field->hasForeignRelation()) {
136+
$this->field->placeHolder = 'Please select a ' . $this->field->getForeignRelation()->name;
137+
}
138+
139+
return $this;
140+
}
141+
127142
/**
128143
* If the field is not visible on the form view, clear the validation.
129144
*

templates/default-collective/create.blade.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="panel-heading clearfix">
88

99
<div class="pull-left">
10-
<h3 class="mt-2 mb-0">Create New [% model_name_class %]</h3>
10+
<h4 class="mt-5 mb-5">Create New [% model_name_class %]</h4>
1111
</div>
1212

1313
<div class="btn-group btn-group-sm pull-right" role="group">

templates/default-collective/edit.blade.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="panel-heading clearfix">
88

99
<div class="pull-left">
10-
<h3 class="mt-2 mb-0">{{ !empty([% model_header %]) ? [% model_header %] : '[% model_name %]'}}</h3>
10+
<h4 class="mt-5 mb-5">{{ !empty([% model_header %]) ? [% model_header %] : '[% model_name %]' }}</h4>
1111
</div>
1212

1313
<div class="btn-group btn-group-sm pull-right" role="group">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<label class="btn btn-default">
2-
Browse <input type="file" name="[% file_name %]" id="[% file_name %]" class="hidden[% class_class %]">
2+
Browse <input type="file" name="[% field_name %]" id="[% field_name %]" class="hidden[% class_class %]">
33
</label>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{!! $errors->first('[% file_name %]', '<p class="help-block">:message</p>') !!}
1+
{!! $errors->first('[% field_name %]', '<p class="help-block">:message</p>') !!}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{!! Form::[% field_type %]('[% field_name %]',[% field_value %], ['class' => 'form-control[% css_class %]',[% min_length %][% max_length %][% min_value %][% max_value %][% required_field %][% placeholder %][% step %]) !!}
1+
{!! Form::[% field_type %]('[% field_name %]',[% field_value %], ['class' => 'form-control[% css_class %]',[% min_length %][% max_length %][% min_value %][% max_value %][% required_field %][% placeholder %][% step %] ]) !!}

0 commit comments

Comments
 (0)