错误:此路由不支持POST方法.支持的方法:GET、HEAD.-使用laravel livewire



我正试图使用Laravel livewire进行图像上传,但当我点击按钮"上传";为了测试功能,这个错误出现在

此路由不支持POST方法。支持的方法:GET,HEAD'

程序:

路线

Route::get('/upload', UploadFoto::class)->name('upload.foto.user');

CONTROLLER(使用dd进行测试(

<?php
namespace AppHttpLivewireUser;
use LivewireComponent;
class UploadFoto extends Component
{
public $foto;

public function render()
{
return view('livewire.user.upload-foto');
}
public function storageFoto()
{
dd('aqui');
}
}

视图@扩展("layouts.app"(

@section('content')

<div>
{{-- To attain knowledge, add things every day; To attain wisdom, subtract things every day. --}}
<form action="#" method="post">
<input type="file" name="foto" id="foto" wire:submit.prevent="storageFoto">
<button type="submit">Upload</button>
</form>
</div>
@endsection

您在此路由上设置了get方法,但上传使用post方法。更改:

Route::post('/upload', UploadFoto::class)->name('upload.foto.user');

请检查,您在表单的错误位置添加了submit

<div>
<form wire:submit.prevent="storageFoto" method="post">
<input type="file" name="foto" id="foto">
<button type="submit">Upload</button>
</form>
</div>

您应该将这几行检查到app文件中

@livewireStyles 
@livewireScripts

将路由方法更改为Post

Route::post('/upload', UploadFoto::class)->name('upload.foto.user');

最新更新