0
votes

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');
1
can you share the code you are using to insert into database?Alex Harris
It would be good to review the How To Ask a Good Question Guide (stackoverflow.com/help/how-to-ask). Seems you need to share a bit more code in order for us to help solve your issue since what you have provide is not enough to help debug.Andrew Nolan
sure i will share the files.David Dacruz
@DavidDacruz you can edit your question with the code so it formats better.Andrew Nolan
@AndrewNolan thanks i followed your advice.David Dacruz

1 Answers

0
votes

Nevermind I got it I was importing csv and not xlsx thanks for the help it uploads fine now