gpt4 book ai didi

php - 找不到列 : 1054 Unknown column '_token' in 'field list' Laravel

转载 作者:可可西里 更新时间:2023-10-31 23:53:40 24 4
gpt4 key购买 nike

我尝试更新我的表类别的记录,但它显示错误

Column not found: 1054 Unknown column '_token'

路线

Route::post('/categorias/edit/{id}', 'CategoryController@update');

Controller

public function update(Request $request, $id)
{
$data = request()->all();
Categoria::where('id', '=', $id)->update($data);
return redirect()->to('categorias');
}

型号

class Categoria extends Model
{
protected $table = 'categoria';
protected $fillable = ['id','codigo','nombre','descripcion','estado'];

表单

{{ Form::open(array('url' => url('categorias/add') , 'class'=>'form-horizontal' , 'id'  => 'formulario' , 'method' => 'POST')) }}

{{ csrf_field() }}
<input id="idcate" name="id" type="hidden" placeholder="" class="form-control input-md" required="">
<input id="txtcodigo" name="codigo" type="text" placeholder="" class="form-control input-md" required="">

<input id="txtnombre" name="nombre" type="text" placeholder="" class="form-control input-md" required="">

<textarea class="form-control" id="txtdescripcion" name="descripcion"></textarea >

<select id="cboestado" name="estado" class="form-control">
<option value="0">NO ACTIVO</option>
<option value="1">ACTIVO</option>
</select>
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<button type="submit" class="btn btn-primary">Guardar</button>
{{ Form::close() }}

记录在表格中,我使用相同的表格来编辑和添加新记录,只是通过单击编辑按钮,我更改了操作

$('#formulario').attr('action', '{{ url("categorias/edit")}}'+ "/"+ $('#idcate').val());

最佳答案

你的错误来自

$data = request()->all();
//which includes '_token'
//coming from csrf_field()

改为做

$data = request()->except(['_token']);
//same as $request->except('_token');

关于php - 找不到列 : 1054 Unknown column '_token' in 'field list' Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42870607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com