From 23dfef114e780bac068c72b4bc50ed5f8cc0d0ee Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 12 Jul 2022 14:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=B9=E5=B9=95=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DanmakuQueryController.php | 29 +++++++++- .../index.blade.php} | 0 .../views/danmaku/search_index.blade.php | 53 +++++++++++++++++++ resources/views/header.blade.php | 2 +- routes/web.php | 1 + 5 files changed, 83 insertions(+), 2 deletions(-) rename resources/views/{danmaku.blade.php => danmaku/index.blade.php} (100%) create mode 100644 resources/views/danmaku/search_index.blade.php diff --git a/app/Http/Controllers/DanmakuQueryController.php b/app/Http/Controllers/DanmakuQueryController.php index 2d6c043..2a9fe68 100644 --- a/app/Http/Controllers/DanmakuQueryController.php +++ b/app/Http/Controllers/DanmakuQueryController.php @@ -2,7 +2,9 @@ namespace App\Http\Controllers; +use App\Models\VideoDanmakus; use App\Models\Videos; +use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; class DanmakuQueryController extends BaseController @@ -10,8 +12,33 @@ class DanmakuQueryController extends BaseController public function index() { $video_list = Videos::query()->withCount("danmakus")->orderByDesc("created_at")->limit(20)->get(); - return view("danmaku", [ + return view("danmaku.index", [ "video_list" => $video_list, ]); } + + public function specific_search(Request $request, string $bvid) + { + $video = Videos::query()->withCount("danmakus")->where("bvid", "=", $bvid)->firstOrFail(); + $keyword = $request->get("keyword", ""); + if ($keyword) { + $query = VideoDanmakus::query()->where("video_bvid", "=", $bvid); + $keyword_split = explode(" ", $keyword); + foreach ($keyword_split as $_keyword) { + if (mb_strlen(trim($_keyword)) > 0) { + $query->where(function ($_query) use ($_keyword) { + $_query->where("content", "like", "%{$_keyword}%", "or")->where("from", "like", "%${_keyword}%", "or"); + }); + } + } + $danmakus = $query->orderBy("created_at", "asc")->get(); + } else { + $danmakus = []; + } + return view("danmaku.search_index", [ + "keyword" => $keyword, + "video" => $video, + "danmakus" => $danmakus, + ]); + } } diff --git a/resources/views/danmaku.blade.php b/resources/views/danmaku/index.blade.php similarity index 100% rename from resources/views/danmaku.blade.php rename to resources/views/danmaku/index.blade.php diff --git a/resources/views/danmaku/search_index.blade.php b/resources/views/danmaku/search_index.blade.php new file mode 100644 index 0000000..34ba8ab --- /dev/null +++ b/resources/views/danmaku/search_index.blade.php @@ -0,0 +1,53 @@ + +
+ +发送人 | +弹幕内容 | +发送时间 | +
+ @switch($danmaku->platform_id)
+ @case(1)
+ |
+ {{$danmaku->content}} | +{{$danmaku->created_at}} | +