这是我的edit.blade文件。请注意From tag action属性。这个好吗?
@extends('admin_theme.master')
@section('title','Add Category')
@section('content')
@if(Auth::check())
<script>
function validselect(){
var ind=document.getElementById('my_select').selectedIndex;
if(ind==0){
alert("please select an Valid Option");
}
}
</script>
<div class="forms">
<div class=" form-grids form-grids-right">
<div class="widget-shadow " data-example-id="basic-forms">
<div class="form-title">
<h4>Ready To ADD:</h4>
</div>
<div class="form-body">
<form class="form-horizontal" action={{route('category.update',$singledata->id)}} method="put">
{{ csrf_field() }}
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Category Name</label>
<div class="col-sm-9">
<input class="form-control" id="inputEmail3" placeholder="Name" type="text" value="{{$singledata->name}}" name="name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Status</label>
<div class="col-sm-9">
<Select class="form-control" id="my_select"onchange="validselect()" name="status">
<option>Select availability</option>
<option value="1" @if($singledata->status==1){{"selected"}} @endif >Active</option>
<option value="0" @if($singledata->status==0){{"selected"}} @endif>DeActive</option>
</Select>
</div>
</div>
<div class="form-group">
</div>
<div class="col-sm-offset-2"> <button type="submit" class="btn btn-default" >Update</button>
</div>
</form>
</div>
</div>
</div>
</div>
@endif
@endsection
这是我在控制器中的更新方法,这里是在$ request对象中找不到编辑页面的输入数据。我改变了像PUT或PATCH这样的html方法,但没有运气:)
public function update(Request $request, $id)
{
$allinput=$request->all();
// dd($allinput);
// dd($allinput);
$data=Category::findorfail($id);
$data->update($allinput);
return view('admin_theme.dynamic_files.category.allCategory');
}
这是我的路线
<?php
Route::get('/', function () {
return view('my_theme.index');
});
Auth::routes();
Route::get('/admin', 'HomeController@index');
Route::resource('category','CategoryController');
在之前(做CRUD)store()方法工作正常,问题是当我更新数据时...我被困在这上面,请帮助我。谢谢提前
答案 0 :(得分:0)
Atlast解决了
在表单标记中添加method =“POST”,并在{{csrf_field()}}之后添加以下行
<input name="_method" type="hidden" value="PATCH">
但为什么这条线需要?不知道。如果有人让我明白,我会感激不尽:)