简体   繁体   English

Laravel模型表单绑定不适用于编辑

[英]Laravel model form binding not working for edit

I have a controller TourCategoryController.php and has edit method: 我有一个控制器TourCategoryController.php并具有编辑方法:

public function edit(TCategory $tCategory)
{
    return view('admin.manage.tour.category.edit')->withCategory($tCategory);
}

And below is the code from my view edit : 下面是我看来的代码edit

<div class="col-sm-4">
    {{Form::model($category,['route' => ['tour-category.update', $category->id ], 'method' => "PUT"]) }}
    <input type="text" class="form-control" id="name" name="name">
    <label for="name">Name</label>
    {{ Form::close() }}
</div>

The trouble I'm having is, the input field is not being filled with form modal binding. 我遇到的麻烦是,输入字段未填充表单模式绑定。

While inspecting the edit form action attribute shows action="http://localhost:8000/manage/tour-category" while it should be like action="http://localhost:8000/manage/tour-category/{id}" 在检查编辑表单时,action属性显示action="http://localhost:8000/manage/tour-category"而它应该类似于action="http://localhost:8000/manage/tour-category/{id}"

Route for the controller: 控制器的路线:

Route::prefix('manage')
->middleware('role:superadministrator|administrator|user')
->group(function () {
         Route::resource('tour-category','TourCategoryController');
});

使用laravel文本字段,而不是纯格式文本字段。

 {{ Form::text('name',null,['class'=>'form-control','id'=>'name']) }}

use 采用

{{ Form::text('name',null,['class'=>'form-control','id'=>'name']) }}

instead of 代替

 <input type="text" class="form-control" id="name" name="name">

If you are not using Form Facades 如果您不使用Form Facades

<div class="col-sm-4">
    <form method="POST" action="{{ route('tour-category.update', $category->id) }}">
        {{ method_field('PUT') }}
        {{ csrf_field() }}

        <label for="name">Name</label>
        <input type="text" id="name" name="name" class="form-control">
    </form>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM