dimanche 6 janvier 2019

array_push() expects parameter 1 to be array null given

I am trying to store a form data into an internal JSON file with this controller code

`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()];

    }
}`

but it still returns with this Error

`array_push() expects parameter 1 to be array null given`

I'm sure it's a pretty simple error but I need some help to correct it



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2FdGlJ5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire