누구든지 내 다음 데이터 삽입 코드의 문제를 해결할 수 있습니까?SQLSTATE [42S22] : 열을 찾을 수 없습니다 : 1054 Laravel의 '필드 목록'에서 'title'알 수없는 열 5.4
SQLSTATE [42S22]없는 컬럼 : 1,054 알 열 '제목' '필드 목록'에 (SQL : (시험 gallery_categories (제목, 설명 CATEGORY_ID, 이미지 updated_at, created_at) 값을 삽입 제목, 시험 정보, 1, 1512370315.jpg, 2017년 12월 4일 6시 51분 55초, 2017년 12월 4일 6시 51분 55초))
나는 두 가지 모델이있다. GalleryModel 중 하나와 GalleryCategoryModel 중 하나입니다. dd($request->all());
을 사용할 때 완벽하게 디버깅합니다.
N.B : 저는 laravel에서 새로운입니다. 여기
GalleryModel 모델
class GalleryModel extends Model
{
protected $table = 'galleries';
protected $primaryKey = 'id';
protected $fillable = ['title', 'description', 'image', 'category_id'];
}
그리고 내 GalleryCategoryModel 모델
class GalleryCategoryModel extends Model
{
protected $table = 'gallery_categories';
protected $primaryKey = 'id';
protected $fillable = ['name'];
}
내 컨트롤러 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);
}
여기에 당신이 당신의 gallery_categories 테이블의 열 이름이 제목을 가지고 있지 않기 때문입니다 내 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>
오류 메시지가 아주 자명하지 않습니까? 테이블'gallery_categories'에 실제로'title'이라는 열이 있습니까? 'GalleryCategoryModel' 객체에'title','description'과'category_id'를 설정하려하기 때문에 당신이 잘못된 모델을 사용하고 있다고 생각합니다. –
이 질문에는 문자 그대로 수십 개의 중복이 있습니다. 해답을 찾으려면 그들을 참조하십시오. –
@Mahbub mind editing (out) 의견 시작을 부탁드립니다. 그것은 "Oh sh \ * t"*에 관한 무례하거나 불쾌감을 주거나,하지 않으면 절제를 위해 플래그가 붙을 수 있습니다. –