SQLSTATE[42S22]:未找到列:Laravel 5.4 中“字段列表”中的 1054 列“标题”未知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47636724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list' in Laravel 5.4
提问by Mahbub
Can anyone help me what is the problem of my following data insert code?
任何人都可以帮助我以下数据插入代码的问题是什么?
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list' (SQL: insert into gallery_categories (title, description, category_id, image, updated_at, created_at) values (Test title, Test details, 1, 1512370315.jpg, 2017-12-04 06:51:55, 2017-12-04 06:51:55))
SQLSTATE[42S22]:未找到列:1054 '字段列表'中的未知列'标题'(SQL:插入到gallery_categories(标题,描述,category_id,图像,updated_at,created_at)值(测试标题,测试详细信息,1,1512370315 .jpg, 2017-12-04 06:51:55, 2017-12-04 06:51:55))
I have two model. One of GalleryModel and other of GalleryCategoryModel. When I use dd($request->all());then it debugging perfect.
我有两个模型。GalleryModel 和 GalleryCategoryModel 之一。当我使用dd($request->all());然后它调试完美。
N.B: I am new in laravel.
注意:我是 Laravel 的新手。
GalleryModel Model
画廊模型模型
class GalleryModel extends Model
{
protected $table = 'galleries';
protected $primaryKey = 'id';
protected $fillable = ['title', 'description', 'image', 'category_id'];
}
And here is my GalleryCategoryModel Model
这是我的 GalleryCategoryModel 模型
class GalleryCategoryModel extends Model
{
protected $table = 'gallery_categories';
protected $primaryKey = 'id';
protected $fillable = ['name'];
}
My controller GalleriesController
我的控制器 GalleriesController
public function create()
{
$categories = GalleryCategoryModel::all();
return view('pages.backend.galleries.create')->withCategories($categories);
}
public function store(StoreGalleryRequest $request)
{
$gallery = new GalleryCategoryModel;
$gallery->title = $request->title;
$gallery->description = $request->description;
$gallery->category_id = $request->category_id;
if($request->hasFile('gallery_image')){
$image = $request->file('gallery_image');
$filename = time() . '.' .$image->getClientOriginalExtension();
$location = public_path('assets/backend/images/' .$filename);
Image::make($image)->resize(500, 350)->save($location);
$gallery->image = $filename;
}
$gallery->save();
Session::flash('success', "Data has been insert success");
return redirect()->route('galleries.index', $gallery->id);
}
Here is my HTML code
这是我的 HTML 代码
<div class="br-section-wrapper">
<h6 class="tx-gray-800 tx-uppercase tx-bold tx-14 mg-b-10">Create New Gallery</h6>
{!! Form::open(array('route' => 'galleries.store', 'data-parsley-validate' => '', 'files' => true)) !!}
{{ csrf_field() }}
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-4">
<div class="form-group margin-top15">
<label for="title">Gallery Title: <span class="tx-danger">*</span></label>
<input type="text" name="title" id="title" class="form-control" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group margin-top15">
<label for="category_id">Select Category: <span class="tx-danger">*</span></label>
<select class="form-control select2 width-100" name="category_id" id="category_id" data-placeholder="Choose one" data-parsley-class-handler="#slWrapper" data-parsley-errors-container="#slErrorContainer" required>
<option label="Choose one"></option>
@foreach($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group margin-top15">
<label for="gallery_image">Gallery Image: <span class="tx-danger">*</span></label>
<input type="file" name="gallery_image" id="gallery_image" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<label for="description">Description: <span class="tx-danger">*</span></label>
<textarea name="description" id="description" class="form-control"></textarea>
</div>
</div>
<div class="form-group margin-top15">
<button type="submit" class="btn btn-info tx-11 pd-y-12 tx-uppercase tx-spacing-2">Create Gallery</button>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
回答by Taha Tariq
This is because you don't have a column named title in your gallery_categories tables.
这是因为在gallery_categories 表中没有名为title 的列。

