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.

0 0 vote
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
2 years ago


Good example code demo,

I think you forgot to include this line in the ContactController.php :

use IlluminateSupportFacadesStorage;

Youness from team Protection Status
Would love your thoughts, please comment.x