稿件查询支持搜索

This commit is contained in:
2025-07-01 11:02:20 +08:00
parent f779c07ebc
commit 37afb22641
2 changed files with 20 additions and 4 deletions

View File

@ -10,13 +10,24 @@ use Illuminate\Routing\Controller as BaseController;
class DanmakuQueryController extends BaseController class DanmakuQueryController extends BaseController
{ {
public function index() public function index(Request $request)
{ {
$video_list = Videos::query() $keyword = $request->get("keyword", "");
$query = Videos::query()
->withCount("danmakus", "bilibili_danmakus", "ixigua_danmakus", "douyin_danmakus", "programs") ->withCount("danmakus", "bilibili_danmakus", "ixigua_danmakus", "douyin_danmakus", "programs")
->orderByDesc("created_at") ->orderByDesc("created_at");
->paginate(10)->withQueryString(); if ($keyword) {
$keyword_split = explode(" ", $keyword);
foreach ($keyword_split as $_keyword) {
$_keyword = trim($_keyword);
if (mb_strlen($_keyword) > 0) {
$query->where("title", "like", "%{$_keyword}%");
}
}
}
$video_list = $query->paginate(10)->withQueryString();
return view("danmaku.index", [ return view("danmaku.index", [
"keyword" => $keyword,
"video_list" => $video_list, "video_list" => $video_list,
]); ]);
} }

View File

@ -7,6 +7,11 @@
</head> </head>
<body> <body>
@include("common.header") @include("common.header")
<form class="max-w xl:max-w-5xl lg:max-w-2xl md:max-w-lg mx-2 md:mx-auto form py-2" action="">
<label for="keyword">查找视频标题,空格隔开查找多个关键词</label>
<input class="border border-black" type="text" name="keyword" id="keyword" value="{{$keyword}}">
<input class="border border-black" type="submit">
</form>
@foreach($video_list as $video) @foreach($video_list as $video)
<div class="max-w xl:max-w-5xl lg:max-w-2xl md:max-w-lg mx-2 md:mx-auto px-2 md:px-4 py-4 bg-white border border-gray-200 rounded-lg shadow-md my-4 dark:bg-gray-800"> <div class="max-w xl:max-w-5xl lg:max-w-2xl md:max-w-lg mx-2 md:mx-auto px-2 md:px-4 py-4 bg-white border border-gray-200 rounded-lg shadow-md my-4 dark:bg-gray-800">
<div> <div>