Php 拉维尔查询例外
嗨,我是编程新手,我已经安装了laravel。我正在尝试导入一个csv文件并将其插入数据库,但我遇到了这个错误 Connection.php第647行中的QueryException: SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“nometablissementnumero”(SQL:select*fromPhp 拉维尔查询例外,php,mysql,sql,laravel,laravel-5,Php,Mysql,Sql,Laravel,Laravel 5,嗨,我是编程新手,我已经安装了laravel。我正在尝试导入一个csv文件并将其插入数据库,但我遇到了这个错误 Connection.php第647行中的QueryException: SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“nometablissementnumero”(SQL:select*from从业者where(nometablissementnumero=0)限制1) 表名正确,我想: INSERT INTO table 'adherents'
从业者
where(nometablissementnumero
=0)限制1)
表名正确,我想:
INSERT INTO table 'adherents' => 'nom',
=> 'etablissement',
=> 'numero'
模型
不管怎样我得到了它我是导入csv而不是xlsx谢谢它上传的帮助现在很好你能分享你用来插入数据库的代码吗?最好回顾一下如何提问指南()。似乎您需要共享更多的代码,以便我们帮助解决您的问题,因为您提供的不足以帮助调试。当然,我将共享这些文件。@DavidDacruz您可以用代码编辑您的问题,使其格式更好。@AndrewNolan谢谢,我听从了您的建议。
<?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);
}
}
<?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');