Я пытаюсь сохранить данные формы во внутренний файл JSON с этим кодом контроллера
function index() {
return view('contact_form');
}
function store(Request $request) {
try {
// my data storage location is project_root/storage/app/data.json file.
$contactInfo = Storage::disk('local')->exists('data.json') ? json_decode(Storage::disk('local')->get('data.json')) : [];
$inputData = $request->only(['name', 'email', 'message','subject']);
$inputData['datetime_submitted'] = date('Y-m-d H:i:s');
array_push($contactInfo,$inputData);
Storage::disk('local')->put('data.json', json_encode($contactInfo));
return $inputData;
} catch(Exception $e) {
return ['error' => true, 'message' => $e->getMessage()];
}
}
но все равно возвращается с этой ошибкой
array_push () ожидает, что параметр 1 будет иметь значение null массива
Я уверен, что это довольно простая ошибка, но мне нужна помощь, чтобы исправить ее