@JohnnyBigodes
The error you're encountering is due to the fact that dot commands, such as ".import," are specific to the SQLite command-line interface (CLI) and cannot be executed directly through Laravel's database connection.
However, you can import a CSV file into a SQLite table using Laravel by utilizing its query builder or raw SQL statements. Here's an example of how you can achieve this:
use Illuminate\Support\Facades\DB;
$file = 'path/to/file.csv';
$tableName = 'your_table_name';
$file = fopen($file, 'r');
$columns = fgetcsv($file);
DB::beginTransaction();
try {
DB::table($tableName)->truncate();
while (($data = fgetcsv($file)) !== false) {
$rowData = array_combine($columns, $data);
DB::table($tableName)->insert($rowData);
}
DB::commit();
} catch (\Exception $e) {
DB::rollback();
throw $e;
} finally {
fclose($file);
}
In this example, we're using Laravel's query builder to truncate the table and then insert the data row by row. The array_combine function is used to associate the column names with the corresponding values for each row.
Make sure to replace 'path/to/file.csv' with the actual path to your CSV file and 'your_table_name' with the desired name of your SQLite table.
By following this approach, you can import the data from the CSV file into a SQLite table using Laravel without relying on dot commands.