Skip to content

Instantly share code, notes, and snippets.

@andyfleming
Last active October 17, 2021 11:15
Show Gist options
  • Save andyfleming/3b15f7ca6719c4705733 to your computer and use it in GitHub Desktop.
Save andyfleming/3b15f7ca6719c4705733 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use Illuminate\Database\DatabaseManager;
class StatsController extends Controller
{
/**
* @return array
*/
public function getLatest()
{
// Resolve dependencies out of container
/** @var DatabaseManager $db */
$db = app('db');
$accountsDatabase = $db->connection('accounts');
$contentDatabase = $db->connection('content');
// Look up 3 newest users and 3 newest blog posts
$threeNewestUsers = $accountsDatabase->select("SELECT * FROM users ORDER BY created_at DESC LIMIT 3");
$threeLatestPosts = $contentDatabase->select("SELECT * FROM blog_posts ORDER BY created_at DESC LIMIT 3");
return [
"new_users" => $threeNewestUsers,
"new_posts" => $threeLatestPosts,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment