Hey Laravelers:
this is my code and I don't know how to fix it:
I try to create a table in the database when I import it I'm using laravel-excel
this is import-model:
<?php
namespace App\Imports;
use App\People;
use Maatwebsite\Excel\Row;
use Maatwebsite\Excel\Concerns\OnEachRow;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
class PeopleIMport implements OnEachRow
{
public function onRow(Row $row)
{
People::firstOrCreate($row->toArray());
}
public function createTable($table_name, $fields = [])
{
if (!Schema::hasTable($table_name)) {
Schema::create($table_name, function (Blueprint $table) use ($fields, $table_name) {
$table->increments('id');
if (count($fields) > 0) {
foreach ($fields as $field) {
$table->{$field['type']}($field['name']);
}
}
$table->timestamps();
});
}
}
}
this is the controller:
<?php
namespace App\Http\Controllers;
use App\People;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use App\Exports\PeopleExport;
use App\Imports\PeopleImport;
use Maatwebsite\Excel\Facades\Excel;
class PeopleController extends Controller
{
public function index()
{
$people = People::all();
return view('people')->with('people', $people);
}
public function import(Request $request)
{
if ($request->file('imported_file')) {
Excel::import(new PeopleImport(), request()->file('imported_file'));
return back();
}
}
public function export()
{
return Excel::download(new PeopleExport(), 'people.xlsx');
}
}
this is the error:
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `people` where (`0` = semester and `1` = Industry and `2` = Data Base Name and `3` = Data Source and `4` = Data Base Description and `5` = Database Url and `6` = Data Dictionary Yes or No or Something? and `7` = Number of Rows and `8` = Number of Continous Variables and `9` = Number of Categorical Variables and `10` = Report (1) or Raw Data? (10) 1-10 scale and `11` = Comments) limit 1)
http://localhost:8000/people/import
Hide solutions
A column was not found
You might have forgotten to run your migrations. You can run your migrations using php artisan migrate.
Pressing the button below will try to run your migrations.
Read more
Run migrations
Database: Running Migrations docs
what I'm trying to do importing randomly excel sheet