123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Http\Controllers;
- use App\Repos\PostRepo;
- use Illuminate\Support\Facades\Redis;
- class PostController extends Controller
- {
- protected PostRepo $postRepo;
- public function __construct(PostRepo $postRepo)
- {
- $this->postRepo = $postRepo;
- }
- // 浏览文章
- public function show($id)
- {
- $post = $this->postRepo->getById($id);
- $views = $this->postRepo->addViews($post);
- return "Show Post #{$post->id}, Views: {$views}";
- }
- // 获取热门文章排行榜
- public function popular()
- {
- $posts = $this->postRepo->trending(10);
- if ($posts) {
- dump($posts->toArray());
- }
- }
- }
|