您好我是编程的新手,我已经安装了laravel我尝试导入csv文件并将其插入数据库但我收到此错误
Connection.php第647行中的QueryException:
SQLSTATE [42S22]:未找到列:1054未知列' nometablissementnumero'在' where子句' (SQL:select * from adherents
其中(nometablissementnumero
= 0)限制1)
表名是正确的我想:
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', 'ExcelController@getImport');
Route::post('/postImport', 'ExcelController@postImport');
答案 0 :(得分:0)
没关系我明白了我导入了csv而不是xlsx感谢你现在上传的帮助