为什么 laravel 中的 store() 更改存储中的文件名?

why store() in laravel change the file name in storage?

我在 laravel 中有此代码来存储图像,但是为什么当我在文件夹中检查图像名称时图像名称发生了变化?!请帮助我,我真的很沮丧!

public function postStore(Request $req){//Bikin toko baru


        $req->image->store('images','public');
        

        $req->validate([
            'name'=>['string','min:5'],
            'address'=>['string','min:10'],
            'description'=>['string','min:20']
            // 'image'=>'mimes:jpg,png,jpeg'

        ]);

来自Laravel Documentation

The store method accepts the path where the file should be stored relative to the filesystem's configured root directory. This path should not contain a file name, since a unique ID will automatically be generated to serve as the file name.

如果您不想自动生成文件名,您可以使用storeAs方法,它接受路径、文件名和磁盘名作为参数:

$path = $request->image->storeAs('images', 'filename.jpg');
$path = $request->image->storeAs('images', 'filename.jpg', 'public');

请试试这个

$path = $request->file('image')->storeAs(
        'images', $request->file('image')->getClientOriginalName()
    );