From d0e816ec6e07a4e2787c71e0e5b27168dffb8d7c Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 15 Jul 2022 21:28:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E6=A0=87=EF=BC=8C=E5=8F=8A=E6=8A=96?= =?UTF-8?q?=E9=9F=B3=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/DanmakuQueryController.php | 5 ++++- app/Models/Videos.php | 15 +++++++++++++++ resources/views/danmaku/index.blade.php | 9 +++++++++ resources/views/danmaku/search_index.blade.php | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DanmakuQueryController.php b/app/Http/Controllers/DanmakuQueryController.php index 206e9f7..dab6964 100644 --- a/app/Http/Controllers/DanmakuQueryController.php +++ b/app/Http/Controllers/DanmakuQueryController.php @@ -11,7 +11,10 @@ class DanmakuQueryController extends BaseController { public function index() { - $video_list = Videos::query()->withCount("danmakus")->orderByDesc("created_at")->paginate(10); + $video_list = Videos::query() + ->withCount("danmakus", "bilibili_danmakus", "ixigua_danmakus", "douyin_danmakus") + ->orderByDesc("created_at") + ->paginate(10); return view("danmaku.index", [ "video_list" => $video_list, ]); diff --git a/app/Models/Videos.php b/app/Models/Videos.php index 1b59d2a..5e73627 100644 --- a/app/Models/Videos.php +++ b/app/Models/Videos.php @@ -20,4 +20,19 @@ class Videos extends Model { return $this->hasMany(VideoDanmakus::class, "video_bvid", "bvid"); } + + public function bilibili_danmakus(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->danmakus()->where("platform_id", "=", 1); + } + + public function ixigua_danmakus(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->danmakus()->where("platform_id", "=", 2); + } + + public function douyin_danmakus(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->danmakus()->where("platform_id", "=", 3); + } } diff --git a/resources/views/danmaku/index.blade.php b/resources/views/danmaku/index.blade.php index 8eaf75f..4690f9e 100644 --- a/resources/views/danmaku/index.blade.php +++ b/resources/views/danmaku/index.blade.php @@ -21,6 +21,15 @@ @if($video->danmakus_count > 0) {{$video->title}} + @if($video->bilibili_danmakus_count > 0) + B站 + @endif + @if($video->ixigua_danmakus_count > 0) + 西瓜视频 + @endif + @if($video->douyin_danmakus_count > 0) + 抖音 + @endif @else {{$video->title}} @endif diff --git a/resources/views/danmaku/search_index.blade.php b/resources/views/danmaku/search_index.blade.php index 48729b2..bf62dd4 100644 --- a/resources/views/danmaku/search_index.blade.php +++ b/resources/views/danmaku/search_index.blade.php @@ -37,6 +37,10 @@ 西瓜视频 {{$danmaku->from}} @break + @case(3) + 抖音 + {{$danmaku->from}} + @break @default {{$danmaku->from}} @break