2017-05-24 57 views
0

嗨,我是在編程新我已經安裝了laravel我試圖導入CSV文件,並將其插入到數據庫,但我得到這個錯誤在Connection.php線Laravel QueryException

QueryException 647:

SQLSTATE [42S22]:柱未找到:在 'where子句' 1054未知列 'nometablissementnumero'(SQL:SELECT * FROM adherents其中(nometablissementnumero = 0)限制1)

表名是正確的I會喜歡:

INSERT INTO table 'adherents' => 'nom', 
           => 'etablissement', 
           => 'numero' 

模型

<?php 
     namespace App; 
     use Illuminate\Database\Eloquent\Model; 
      class Adherent extends Model { 
    protected $fillable = [ 'nom', 'etablissement', 'numero', ]; 
    public $timestamp = false; 
    } 

的粘附控制器

<?php 
    namespace App\Http\Controllers; 

    use Illuminate\Http\Resquest; 
    use App\Http\Requests; 
    use App\Http\Controllers\Controller; 
    use App\Adherent; 

    class AdherentController extends Controller{ 

    /** 
    * Display a listing for the ressource 
    * 
    * @return \Illuminate\Http\Response 
    **/ 

    public function index(){ 
    $adherents = Adherent::all(); 
    return view('adherents.index')->with('adherents', $adherents); 
    } 
    } 

excel的控制器

<?php namespace App\Http\Controllers; 
    use Illuminate\Http\Request; 
    use App\Http\Requests; 
    use App\Http\Controllers\Controller; 
    use App\Adherent; 
    use Illuminate\Support\Facades\Input; 
    use DB; use Excel; 
    class ExcelController extends Controller { 

    public function getImport(){ 

    return view('excel.importAdherent'); 
    } 

    public function postImport(){ 
    Excel::load(Input::file('adherent'),function($reader){ 
    $reader->each(function($sheet){ 
    Adherent::firstOrCreate($sheet->toArray()); 
    }); 
    }); 
    return back(); 
    } 
    } 

路線

Route::resource('adherent', 'AdherentController'); 
    Route::get('/getImport', '[email protected]'); 
    Route::post('/postImport', '[email protected]'); 
+0

你能分享你正在使用插入到數據庫的代碼? –

+0

這將是很好的檢討如何提出一個很好的問題指南(https://stackoverflow.com/help/how-to-ask)。看來你需要共享更多的代碼,以便我們幫您解決問題,因爲你所擁有的提供是不夠的,幫助調試。 –

+0

當然我會分享這些文件。 –

回答

0

沒關係我得到了它,我導入CSV和它上傳精細的幫助不XLSX感謝現在

相關問題