Last active
October 17, 2021 11:15
-
-
Save andyfleming/3b15f7ca6719c4705733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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