When a new User is created, I save the username and password (no hashed) in a json file as well as in the DB, so every time I'm appending new users to the json file:
{
"user3": "demo"
} {
"user4": "demo"
} {
"user4": "demo"
} {
"user5": "demo"
}
the code:
$data = array($request->input('username') => $request->input('password'));
$datos = json_encode($data);
File::append(storage_path('archivos/datos.json'), $data);
of course the format above isn't valid json, how could i get this
[{
"user3": "demo"
}, {
"user4": "demo"
}, {
"user4": "demo"
}, {
"user5": "demo"
}, {
"user5": "demo"
}, {
"user5": "demo"
}, {
"user7": "demo"
}, {
"user8": "demo"
}]
and read it using foreach like this:
$result = File::get(storage_path('archivos/datos.json'));
$result = json_decode($result);
foreach($result as $key=>$item){
echo $key .''. $item;
}