get data from different db laravel code example
Example 1: laravel 8 app with more than one database
$blogs = DB::connection('mysql2')->table("blog")->get();print_r($blogs);
Example 2: laravel 8 app with more than one database
<?php class BlogController extends BaseController{ public function getRecord() { $blogModel = new Blog; $blogModel->setConnection('mysql2'); $find = $blogModel->find(1); return $find; }}