Laravel create a json file and append content to it.

In this post, I would like to show you creating a JSON file and appending content to it whenever somebody submits a form. For this tutorial, I am gonna use Laravel 5.6 version.

Let’s create a brand new Laravel project via Composer Create-Project command. lets issue following command from your terminal:

It will create a directory called jsonAppendDemo and download all the Laravel project files and its dependencies.

After completing setup process, create a view file called contact_form.blade.php in resources/views directory with following HTML.

Create a controller called ContactController.php with below command:

After creating controller lets define following methods, index is to show the contact form and store method is to handle the submitted data.

All set lets define routes to access the form and to process the submitted data in your web.php route file.

Now start the php server with below command

Once it is started, if you visiting http://localhost:8000, you should see the following page in your browser

Laravel create a json file and append content to it.

Once you submit the form data will be stored in the project_root/storage/app/data.json file.
Here is my data.json file.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status