Php Laravel Nova图像存储名称问题
所以,我试图存储一个图像,它是通过博客文章上传到一个特定的文件夹,其原始文件名 图像已保存到正确的文件路径,但正在将其保存为随机字符串名称。我的代码如下:Php Laravel Nova图像存储名称问题,php,laravel,laravel-nova,Php,Laravel,Laravel Nova,所以,我试图存储一个图像,它是通过博客文章上传到一个特定的文件夹,其原始文件名 图像已保存到正确的文件路径,但正在将其保存为随机字符串名称。我的代码如下: public function fields(Request $request) { return [ ID::make('id')->sortable(), Text::make('URL ID', 'id')->hideFromIndex(), Text::make('T
public function fields(Request $request)
{
return [
ID::make('id')->sortable(),
Text::make('URL ID', 'id')->hideFromIndex(),
Text::make('Title', 'title'),
select::make('Market Type', 'market_id')->options([
'church' => 'Church',
'school' => 'School',
'business' => 'Business',
'municipal' => 'Municipal'
]),
Trix::make('Body', 'text'),
Image::make('Image', 'main_image')
->disk('blog')
->storeOriginalName('main_image')
->maxWidth(200)
->prunable(),
];
}
->storeOriginalName()与保存的文件名无关,而是与浏览器在“详细信息”页面的“图像”字段中单击“下载”时获取的文件名有关
更改文件名最简单的方法是使用->store()方法,如下所示:
Image::make('Image', 'main_image')
->store(function (Request $request, $model) {
$filename = $request->main_image->getClientOriginalName();
$request->main_image->storeAs('/', $filename, 'blog');
return [
'main_image' => '/' . $filename,
'main_image_name' => $request->main_image->getClientOriginalName()
];
})
->maxWidth(200)
->storeOriginalName('main_image_name')
->prunable(),