本文介绍了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.
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'));
}
此错误发生在下一行.
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`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!