Closed mddickens closed 4 years ago
File by default is not shown on index and I not sure if I can reproduce the issue.
Please provide an example to reproduce the issue.
The above explains it clearly. When the file is uploaded, I store the original name (as shown above), but I get the stored name on the file upload button field. And this shows the renaming issue as well.
Show us your Nova Resource's code, plz. :-)
Here you go. Please note that I added the storeAs call after I posted this comment this morning and while it addressed the extension renaming issue, it did not change the display of the stored name.
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\File;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Http\Requests\NovaRequest;
class PrintFile extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $priority = 20;
public static $group = 'Shops';
public static $tableStyle = 'tight';
public static $model = \App\Models\PrintFile::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id', 'name', 'description'
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')
->sortable(),
BelongsTo::make('Shop'),
Text::make('Name')
->exceptOnForms(),
Text::make('Description'),
File::make('Print File', 'file_path')
->storeOriginalName('name')
->storeSize('file_size')
->storeAs(function(Request $request) {
return sha1($request->file_path->getClientOriginalName()) . '.' . pathinfo($request->file_path->getClientOriginalName(), PATHINFO_EXTENSION);
})
->deletable(false)
->hideFromIndex()
->disk('public')
->required()
->prunable(),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
{
return [];
}
}
From what I understand here, you expect that the original name to be preserved since you used storeOriginalName()
, however this operation has been overridden when you combine that with storeAs()
. You should be able to keep the original file name if you used
File::make('Print File', 'file_path')
->storeSize('file_size')
->storeAs(function(Request $request) {
return $request->file_path->getClientOriginalName() . '.' . pathinfo($request->file_path->getClientOriginalName(), PATHINFO_EXTENSION);
})
->deletable(false)
->hideFromIndex()
->disk('public')
->required()
->prunable(),
I found that you can use the displayUsing
function to show the original filename:
File::make('file_path')
->storeOriginalName('original_filename')
->displayUsing(function ($value) {
return $this->original_filename;
})
Just make sure the displayUsing
function uses the same column as the original filename is being stored in.
The solution above no longer works, looks like the file field has stopped respecting displayUsing
.
@alexanderchr submit new bug report with full reproducing code. We don't review or reopen closed issues.
Description:
After uploading a file and storing the original name of the file, Nova displays the stored name of the file in the detail and form views. It correctly shows the original name of the file in the index view, but then incorrectly shows the stored name in the detail and form views.
Detailed steps to reproduce the issue on a fresh Nova installation:
Upload a file and view it in the various views