Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Laravel Store JSON Format Data in Database

 

Create Model and migration

Now generate a model and migration file just running the below command.

php artisan make:model Post -m

app/database/migration

public function up()
 {
     Schema::create('posts', function (Blueprint $table) {
         $table->increments('id');
         $table->json('data')->nullable();
         $table->timestamps();
     });
 }

After creating and updating the code in your migration file now run the below command and check your database where your show a posts table is created along with users and reset_password tables.

php artisan migrate

 

Create Controller

Now create a new controller just running the below command.

php artisan make:controller PostController 

After running above command put the below command on it.

 
<?php
 
namespace App\Http\Controllers;
use App\Post;
use Redirect,Response;
use Illuminate\Http\Request;
 
class PostController extends Controller
{
   public function index()
   {
      return view('create');
   }  
 
  public function store(Request $request)
  {
      $data = json_encode($request);
      Post::create($data);

      return back()->withSuccess('Data successfully store in json format');
  }
 
}

 

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon