SQLSTATE [42S22]:找不到列:1054“字段列表"中的未知列"category"(SQL:update`articles set`updated_at`) [英] SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category' in 'field list' (SQL: update `articles` set `updated_at`)

查看:135
本文介绍了SQLSTATE [42S22]:找不到列:1054“字段列表"中的未知列"category"(SQL:update`articles set`updated_at`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个桌子

  • 文章
  • 类别

我有一个ArticleController.我要编辑表格.但是会出错.

I have a ArticleController. I want to edit the form. But it get errors.

SQLSTATE [42S22]:找不到列:1054中的未知列'category' '字段列表'(SQL:更新articles设置updated_at = 2017-12-21 11:50:12,category = 1其中id = 1)

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category' in 'field list' (SQL: update articles set updated_at = 2017-12-21 11:50:12, category = 1 where id = 1)

ArticleController.php

ArticleController.php

public function update(ArticleRequest $request, Article $article)
    {
        $file = $request->file('images');
        $inputs = $request->all();
        $article->categories()->sync(request('category'));

        if($file) {
            $inputs['images'] = $this->uploadImages($request->file('images'));
        } else {
            $inputs['images'] = $article->images;
            $inputs['images']['thumb'] = $inputs['imagesThumb'];

        }

        unset($inputs['imagesThumb']);
        $article->update($inputs);

        return redirect(route('articles.index'));
    }

此错误发生在下一行.

$ article-> update($ inputs);

$article->update($inputs);

edit.blade.php

edit.blade.php

<select name="category[]" class="form-control" id="category" title=" Select your a categories..." multiple>
      @foreach( $categories as $id => $name )
               <option value="{{ $id }}" {{ in_array($id , $article->categories()->pluck('id')->toArray()) ? 'selected' : '' }}>{{ $name }}</option>
      @endforeach
</select>

类别

class Category extends Model
{
    protected $fillable = ['name', 'slug'];

    public function articles()
    {
        return $this->belongsToMany(Article::class);
    }
}

文章

public function categories()
    {
        return $this->belongsToMany(Category::class);
    }

推荐答案

您的articles表中没有名为category的列.你能发表你的文章表迁移吗?

Your articles table doesn't have a column called category. Can you post your article table migration please

这篇关于SQLSTATE [42S22]:找不到列:1054“字段列表"中的未知列"category"(SQL:update`articles set`updated_at`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆