I have file txt (data.txt) with this value :
{"id":"1","title":"first Testing","completed":"Yes"}
{"id":"2","title":"Second Testing","completed":"no"}
{"id":"3","title":"Third Testing","completed":"no"}
id
title
completed
Read file and convert it to PHP Array
$arrays = json_decode(file_get_contents('data.txt'), true);
Then with simple foreach
foreach($arrays as $array) {
$myObject = new Model();
$myObject->id = $array['id'];
$myObject->title = $array['title'];
$myObject->completed = $array['completed'];
$myObject->save();
}
Or you could do it straightfoward if you defined $fillable
attributes
foreach($arrays as $array)
Model::create($array);
Using Query Builder
DB::table('data')->insert($arrays);