diff --git a/app/Http/Controllers/DanmakuQueryController.php b/app/Http/Controllers/DanmakuQueryController.php index 90a7dd9..2d6c043 100644 --- a/app/Http/Controllers/DanmakuQueryController.php +++ b/app/Http/Controllers/DanmakuQueryController.php @@ -2,12 +2,16 @@ namespace App\Http\Controllers; +use App\Models\Videos; use Illuminate\Routing\Controller as BaseController; class DanmakuQueryController extends BaseController { public function index() { - return view("under_construct"); + $video_list = Videos::query()->withCount("danmakus")->orderByDesc("created_at")->limit(20)->get(); + return view("danmaku", [ + "video_list" => $video_list, + ]); } } diff --git a/app/Models/VideoDanmakus.php b/app/Models/VideoDanmakus.php new file mode 100644 index 0000000..a08225e --- /dev/null +++ b/app/Models/VideoDanmakus.php @@ -0,0 +1,14 @@ +belongsTo(Videos::class, "video_bvid", "bvid"); + } +} diff --git a/app/Models/Videos.php b/app/Models/Videos.php index e9d62fe..1b59d2a 100644 --- a/app/Models/Videos.php +++ b/app/Models/Videos.php @@ -15,4 +15,9 @@ class Videos extends Model { return $this->hasManyThrough(Programs::class, ProgramVideos::class, "video_bvid", "bvid", "id", "program_id"); } + + public function danmakus(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(VideoDanmakus::class, "video_bvid", "bvid"); + } } diff --git a/resources/views/danmaku.blade.php b/resources/views/danmaku.blade.php new file mode 100644 index 0000000..29cf7d1 --- /dev/null +++ b/resources/views/danmaku.blade.php @@ -0,0 +1,34 @@ + +
+ +视频标题 | +弹幕条数 | +操作 | +
{{$video->title}} | +{{$video->danmakus_count}} | ++ @if($video->danmakus_count > 0) + 详情 + @else + 无弹幕 + @endif + | +