SQLSTATE [42S22]:找不到列:1054未知列'_method'

时间:2019-12-29 17:05:47

标签: mysql laravel-6

我真的不明白为什么这个 @method('PUT')在我的SQL中执行未知列'_method'的原因。我将在下面显示所有可能导致此错误的代码。 Laravel版本6.2。

  

SQLSTATE [42S22]:找不到列:1054中的未知列'_method'   'where子句'(SQL:更新setups设置_method = PUT,id = 1,   image = admitad-e1504616712278.png,meta_title =测试,   address =测试,contact = testing @ testing,email =测试,   social = [“测试”,“测试”],updated_at = 2019-12-29 15:40:21   _method = PUT)

2019_12_23_171326_create_setups_table.php

public function up()
    {
        Schema::create('setups', function (Blueprint $table) {
            $table->increments('id');
            $table->string('image')->nullable();
            $table->string('meta_title');
            $table->string('address');
            $table->string('contact');
            $table->string('email');
            $table->string('social');
            $table->timestamps();
        });
    }

edit.blade.php

<form class="card-body" method="POST" action="{{ route('setups.update', $data->id) }}">
  @csrf
  @method('PUT')
<input type="hidden" name="tbl" value="{{encrypt('setups')}}">
<input type="hidden" name="id" value="{{ $data->id }}">

  <div class="col-sm-3">
    <div class="form-group" style="left: 5px; padding: 30px 0 30px">
      <input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none">
      <img id="output" width="150" style="box-shadow: 0px 16px 18px -4px rgba(0,0,0,0.17);"/>
      <label class="card-title" for="file" style="cursor: pointer; padding: 10px 0 0px">Upload Logo</label>
    </div>
  </div>
    <div class="row">
      <div class="col-md-12">
        <div class="form-group">
          <label class="bmd-label-floating">Site title</label>
          <input type="text" name="meta_title" value="{{ $data -> meta_title }}" class="form-control">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <label class="bmd-label-floating">Address</label>
          <input type="text" name="address" value="{{ $data -> address }}" class="form-control">
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <label class="bmd-label-floating">Contant number</label>
          <input type="email" name="contact" value="{{ $data -> contact }}" class="form-control">
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="form-group">
          <label class="bmd-label-floating">Email</label>
          <input type="text" name="email" value="{{ $data -> email }}" class="form-control">
        </div>
      </div>
      </div>
    <div class="row">
      <div class="col-md-12" id="socialGroup">
        @foreach($socials as $social)
        <div class="form-group socialField">
        <label class="bmd-label-floating">Social Links</label>
          <input type="text" name="social[]" value="{{ $social }}" class="form-control">
          <a href="#" class="addField"><i class="fa fa-plus"></i></a>
        </div>
        @endforeach
        <div class="alert alert-danger" id="socialError">
        <p><strong>Sorry! </strong>You've reached the max number for social links form.</p>
        </div>
      </div>
    </div>
    <button type="submit" class="btn btn-primary pull-right">Update Profile</button>
    <div class="clearfix"></div>
  </form>

SetupController.php

public function update(Request $request, Setup $setup)
{
    $data = Input::except('_token', 'submit');
    $tbl = decrypt($data['tbl']);
    unset ($data['tbl']);

    if(!empty($data['image'])){
      if(Input::hasFile('image')){
        $data['image'] = $this->upload($data['image'], $tbl);
      }
    }

    $data['updated_at'] = date('Y-m-d H:i:s');
    DB::table($tbl)->where(key($data), reset($data))->update($data);

    session::flash('message','SetupController updated successfully!!!');
    return redirect()->route('setups.index');
}

web.php

Route :: resource('setups','SetupController');

1 个答案:

答案 0 :(得分:1)

@method('PUT') 

始终打印

<input name="_method" type="hidden" value="PUT">

插入到源html中,如果您不想使用此代码,则可以删除它,或者您想消除它们,在代码中再添加一个值:

$data = Input::except('_token', 'submit','_method');