我正在尝试使用 Laravel 中的 Blade 组件创建一个表单,但在使用 PUT 方法时它不起作用。但是,当我切换到常规 HTML 表单时,一切正常。以下是我当前的设置:
// views/pages/admin/category/edit.blade.php
@extends("templates.admin")
@section("title")
Category Edit
@endsection
@section("content")
@component("organisms.form", ["action" => "/admin/category/{{$category->id}}", "method" => "PUT"])
@slot("fields")
@include(
"atoms.inputs.text-input",
[
"label" => "Category Name",
"id" => "name",
"name" => "name",
"class" => "mb-4",
"value" => $category->name,
"placeholder" => "Novel",
]
)
@endslot
@slot("buttons")
@include("atoms.buttons.anchor-white", ["href" => "/admin/category", "text" => "Back"])
@include("atoms.buttons.indigo", ["type" => "submit", "text" => "Change"])
@endslot
@endcomponent
@endsection
叶片形式组件
// views/organisms/form.blade.php
<form action="{{ $action }}" method="POST">
@csrf
@method("put")
{{-- Error Messages --}}
@if ($errors->any())
@include("molecules.form-error-message", ["errors" => $errors])
@endif
{{-- Fields --}}
{{ $fields }}
{{-- Buttons --}}
{{ $buttons }}
</form>
工作常规表格示例:
<form action="/admin/category/{{$category->id}}" method="POST">
@csrf
@method('PUT')
@include(
"atoms.inputs.text-input",
[
"label" => "Category Name",
"id" => "name",
"name" => "name",
"class" => "mb-4",
"value" => $category->name,
"placeholder" => "Novel",
]
)
<a href="/admin/category" class="btn btn-white">Back</a>
<button type="submit" class="btn btn-indigo">Change</button>
</form>
我尝试过的:
可能是什么问题?
任何关于为什么表单组件失败但常规表单有效的帮助将不胜感激。谢谢!
尝试使用大写的方法名称,例如
@method("put")
到 @method("PUT")