Laravel & inertia.js 文件下载

Laravel & inertia.js file download

我将文件上传到数据库并使用“php artisan storage:link”创建了存储 link,一切正常,但是当我想下载文件时遇到此错误

这是我的代码

路线

Route::get('/download/{id}', [\App\Http\Controllers\SubjectController::class, 'downloadFile'])->name('subject.download');

Vue.js

<inertia-link :href="'/download/'+slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
      <Icon name="download"></Icon>
</inertia-link>

控制者

    public function downloadFile($id) {
        $file = Upload::find($id);
        $subjectCode = $file->subject()->get()->map->only('name','code')->first()['code'];
        $subjectName = $file->subject()->get()->map->only('name','code')->first()['name'];
        return response()->download(storage_path('app/public/documents/'.Str::upper($subjectCode.'_'.$subjectName).'/'.$file->file), 'public');
    }

替换

<inertia-link :href="'/download/'+slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
                                    <Icon name="download"></Icon>
                                </inertia-link>

<a :href="'/download/' + slide.id" class="rounded-lg bg-gray-200 px-4 py-1">
    <Icon name="download"></Icon>
</a>

那么它不会被inertia处理,它会让你下载文件