Skip to content

Commit 891cb74

Browse files
committed
docs: quick start with date format
1 parent 93de214 commit 891cb74

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@ composer require yajra/laravel-sql-loader:^1.0
3030

3131
## Quick Start
3232

33-
Create a CSV file named `employees.csv` inside `database/files` directory.
34-
35-
```csv
36-
NAME,DEPT_ID
37-
John,1
38-
Jane,1
39-
"Jim, K",2
40-
Joe,2
41-
```
42-
43-
Create a route to test the package.
33+
Below is a quick example of how to use the package:
4434

4535
```php
4636
Route::get('sql-loader', function () {
@@ -49,19 +39,26 @@ Route::get('sql-loader', function () {
4939
$table->id();
5040
$table->string('name');
5141
$table->integer('dept_id');
42+
$table->timestamps();
5243
});
5344

45+
Yajra\SQLLoader\CsvFile::make(database_path('files/employees.csv'), 'w')
46+
->headers(['name', 'dept_id', 'created_at', 'updated_at'])
47+
->insert([
48+
['John Doe', 1, now(), now()],
49+
['Jane Doe', 2, now(), now()],
50+
['John Doe', 1, now(), now()],
51+
['Jane Doe', 2, now(), now()],
52+
]);
53+
5454
$loader = Yajra\SQLLoader\SQLLoader::make();
5555
$loader->inFile(database_path('files/employees.csv'))
56-
->options(['skip=1'])
57-
->mode(Yajra\SQLLoader\Mode::TRUNCATE)
58-
->into('employees', [
59-
'name',
60-
'dept_id',
61-
])
56+
->dateFormat('YYYY-MM-DD HH24:MI:SS')
57+
->withHeaders()
58+
->into('employees')
6259
->execute();
6360

64-
return nl2br($loader->logs());
61+
return DB::table('employees')->get();
6562
});
6663
```
6764

0 commit comments

Comments
 (0)