Hi I'm new at programing and I have installed laravel I'm trying to import a csv file and insert it to the database but i get this error
QueryException in Connection.php line 647:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'nometablissementnumero' in 'where clause' (SQL: select * from adherents
where (nometablissementnumero
= 0) limit 1)
The table name is correct I would like to:
INSERT INTO table 'adherents' => 'nom',
=> 'etablissement',
=> 'numero'
Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Adherent extends Model {
protected $fillable = [ 'nom', 'etablissement', 'numero', ];
public $timestamp = false;
}
The adherent controller
<?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);
}
}
the excel controller
<?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();
}
}
Routes
Route::resource('adherent', 'AdherentController');
Route::get('/getImport', 'ExcelController@getImport');
Route::post('/postImport', 'ExcelController@postImport');