Skip to content

Commit 4875b8a

Browse files
committed
Fixes #71, #75
1 parent 1814814 commit 4875b8a

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/CodeGeneratorServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function boot()
1919

2020
// publish the config base file
2121
$this->publishes([
22-
$dir . 'config/codegenerator.php' => config_path('laravel-code-generator.php'),
22+
$dir . 'config/laravel-code-generator.php' => config_path('laravel-code-generator.php'),
2323
], 'config');
2424

2525
// publish the default-template

src/HtmlGenerators/HtmlGeneratorBase.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,28 @@ protected function getShowRowHtmlField($stub, Field $field)
128128
{
129129
$this->replaceFieldName($stub, $field->name)
130130
->replaceModelName($stub, $this->modelName)
131-
->replaceRowFieldValue($stub, $this->getFieldAccessorValue($field, 'show'))
131+
->replaceRowFieldValue($stub, $this->getFieldValueForShow($field))
132132
->replaceFieldTitle($stub, $this->getTitle($field->getLabel(), true));
133133

134134
return $stub;
135135
}
136136

137+
/**
138+
* Gets the value to use in the show view
139+
*
140+
* @param Field $field
141+
*
142+
* @return string
143+
*/
144+
protected function getFieldValueForShow(Field $field)
145+
{
146+
if ($field->isFile()) {
147+
return sprintf("asset('storage/' . %s)", $this->getFieldAccessorValue($field, 'show'));
148+
}
149+
150+
return $this->getFieldAccessorValue($field, 'show');
151+
}
152+
137153
/**
138154
* Gets header cells' html code for the index view using the current fields colelction.
139155
* If an value is passed, it will only generate the raws based on the given fields

src/Models/Field.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ public function getAccessorValue($variable, $view = null)
623623
}
624624

625625
if ($this->isFile()) {
626-
return sprintf("basename(%s)", $fieldAccessor);
626+
return $fieldAccessor;
627627
}
628628

629629
return $fieldAccessor;

templates/default-collective/controller-upload-method-5.3.stub

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
return '';
1313
}
1414

15-
return $file->store(config('laravel-code-generator.files_upload_path','uploads'), config('filesystems.default'));
15+
$fileName = sprintf('%s.%s', uniqid(), $file->getClientOriginalExtension());
16+
$destinationPath = config('laravel-code-generator.files_upload_path','uploads');
17+
$path = $file->move($destinationPath, $fileName);
18+
19+
return $destinationPath . '/' . $fileName;
1620
}

templates/default/controller-upload-method-5.3.stub

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
return '';
1313
}
1414

15-
return $file->store(config('laravel-code-generator.files_upload_path','uploads'), config('filesystems.default'));
15+
$path = config('laravel-code-generator.files_upload_path', 'uploads');
16+
$saved = $file->store('public/' . $path, config('filesystems.default'));
17+
18+
return substr($saved, 7);
1619
}

0 commit comments

Comments
 (0)