You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browser type and version: Google Chrome 108.0.5359.125
Description:
Using a File field with storeOriginalName doesn't work when you use hasOne and attempt to create the resource inside another related resource (Which implements the HasOne field). On this case, the given error is Call to a member function getClientOriginalName() on null
However, it works directly on the resource creation.
Detailed steps to reproduce the issue on a fresh Nova installation:
Assume you have 2 resources: DocumentHolder and DocumentVersion. DocumentHolder hasOne DocumentVersion (defined as latestOfMany)
class DocumentVersion extends Model
{
use HasFactory, HasUlids;
public function holder()
{
return $this->belongsTo(DocumentHolder::class, 'document_holder_id');
}
}
....
class DocumentHolder extends Model
{
use HasFactory, HasUlids;
protected $fillable = ['id'];
public function versions()
{
return $this->hasMany(DocumentVersion::class, 'document_holder_id');
}
public function latestVersion()
{
return $this->hasOne(DocumentVersion::class, 'document_holder_id')->latestOfMany();
}
}
And also a nova resource for each model, which has the following fields:
class DocumentVersion extends Resource
{
public function fields(NovaRequest $request)
{
return [
ID::make()->hideFromIndex(),
Text::make( 'Name'),
Text::make('Version'),
Date::make('Date')
->exceptOnForms(),
File::make('File')
->storeOriginalName('filename')
->path('/documents'),
Text::make('Filename')->exceptOnForms(),
];
}
}
...
class DocumentHolder extends Resource
{
public function fields(NovaRequest $request)
{
return [
ID::make()->onlyOnForms(),
Text::make('Name', 'latestVersion.name')
->onlyOnIndex(),
File::make('File', 'latestVersion.file')
->storeOriginalName('filename')
->path('/documents/')
->onlyOnIndex(),
Text::make('Current version', 'latestVersion.version_name')
->onlyOnIndex(),
Date::make('Current version date', 'latestVersion.version_date')
->onlyOnIndex(),
HasOne::make('Current version', 'latestVersion', 'App\Nova\DocumentVersion'),
HasMany::make('Versions', 'versions', 'App\Nova\DocumentVersion'),
];
}
}
It works when you try to create a DocumentVersion (/nova/resources/document-versions/new), and the original name is stored properly. However, when you attempt to create a version through DocumentHolder (/nova/resources/document-holders/new), this happens:
This discussion was converted from issue #5191 on December 29, 2022 01:26.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
Using a File field with storeOriginalName doesn't work when you use hasOne and attempt to create the resource inside another related resource (Which implements the HasOne field). On this case, the given error is
Call to a member function getClientOriginalName() on null
However, it works directly on the resource creation.
Detailed steps to reproduce the issue on a fresh Nova installation:
Assume you have 2 resources: DocumentHolder and DocumentVersion. DocumentHolder hasOne DocumentVersion (defined as latestOfMany)
And also a nova resource for each model, which has the following fields:
It works when you try to create a DocumentVersion (/nova/resources/document-versions/new), and the original name is stored properly. However, when you attempt to create a version through DocumentHolder (/nova/resources/document-holders/new), this happens:
Beta Was this translation helpful? Give feedback.
All reactions