Laravel 和惯性.js 文件下载

2024-04-04

I uploaded a file to the database and created Storage link using "php artisan storage:link" and everything work perfectly but when I want to download the file I face this error enter image description here

这是我的代码

route

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');
    }

replace

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

to

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Laravel 和惯性.js 文件下载 的相关文章

随机推荐