![](/img/trans.png)
[英]The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel 8
[英]error: The POST method is not supported for this route. Supported methods: GET, HEAD. - using laravel livewire
我正在嘗試使用 Laravel livewire 上傳圖片,但是當我點擊“上傳”按鈕來測試功能時出現此錯誤
此路由不支持 POST 方法。 支持的方法:GET、HEAD'
節目:
路線
Route::get('/upload', UploadFoto::class)->name('upload.foto.user');
CONTROLLER(使用 dd 進行測試)
<?php
namespace App\Http\Livewire\User;
use Livewire\Component;
class UploadFoto extends Component
{
public $foto;
public function render()
{
return view('livewire.user.upload-foto');
}
public function storageFoto()
{
dd('aqui');
}
}
查看@extends('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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.