简体   繁体   中英

Laravel model form binding not working for edit

I have a controller TourCategoryController.php and has edit method:

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

And below is the code from my view 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}"

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

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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