-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvModel.php
More file actions
39 lines (32 loc) · 867 Bytes
/
Copy pathCsvModel.php
File metadata and controls
39 lines (32 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Waad\Truffle\Enums\DataType;
use Waad\Truffle\Truffle;
/**
* Load records from a CSV file.
*/
class Employee extends Model
{
use Truffle;
protected $fillable = ['name', 'email', 'department'];
protected $schema = [
'id' => DataType::Id,
'name' => DataType::String,
'email' => DataType::String,
'department' => DataType::String,
];
/**
* Using $truffleFile property (auto-detected format):
* protected $truffleFile = __DIR__ . '/../data/employees.csv';
*
* Or load explicitly via getRecords():
*/
public function getRecords(): array
{
return $this->fromCsvFile(__DIR__ . '/../data/employees.csv');
}
}
// Usage:
// Employee::all();
// Employee::where('department', 'Engineering')->get();