2017-12-04 47 views
-1

私の次のデータ挿入コードの問題は何ですか?SQLSTATE [42S22]:列が見つかりません:1054 Laravelの 'フィールドリスト'に 'タイトル'がありません5.4

SQLSTATE [42S22]:カラムが見つかりません: 'フィールドリスト' で1054不明な列 'タイトル'(SQL:gallery_categories(タイトル、 説明、CATEGORY_ID、画像、updated_atの、のcreated_at)値(試験挿入 タイトル、テストの詳細、1、1512370315.jpg、2017年12月4日午前6時51分55秒、 2017年12月4日午前6時51分55秒))

私は2つのモデルがあります。 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> 
+4

エラーメッセージはかなりわかりませんか?あなたのテーブル 'gallery_categories'には実際に' title'という列がありますか? 'GalleryCategoryModel'オブジェクトに' title'、 'description'、' category_id'を設定しようとしているので間違ったモデルを使っていると思います。 –

+1

この質問には、文字通り重複が数多くあります。答えはそれらを参照してください。 –

+1

@Mahbub mind editing(out)あなたのコメントの開始をお願いしますか?それは* "Oh sh \ * t" *についての、失礼/不快、または実行されていない場合の緩和のフラグが立てられる可能性があります。 –

答えて

6

です。

関連する問題