Home » Php » Store Form data to mysql as JSON in Laravel

Store Form data to mysql as JSON in Laravel

Posted by: admin May 15, 2018 Leave a comment

Questions:

I am new to laravel and I want to know how to store my form input as a JSON format into mysql database.

Basically I want to know the complete flow from Blade template to database to store the JSON.

Sample Form:

<div class="container">
  <form action="action_page.php">

    <label for="fname">First Name</label>
    <input type="text" id="fname" name="firstname" placeholder="First Name">

    <label for="lname">Last Name</label>
    <input type="text" id="lname" name="lastname" placeholder="Last Name">

    <label for="subject">Subject</label>
    <textarea id="subject" name="subject" placeholder="Subject" style="height:300px"></textarea>

    <input type="submit" value="Submit">

  </form>
</div>

Sample JSON that I want to store in the database

{ "firstname":"John", "lastname":"Immanuel",  "subject":"This is a test msg" }
Answers: